From 01d5b2d552619dadfaf6bc969f610504637a0ef7 Mon Sep 17 00:00:00 2001 From: kalsteve Date: Sun, 28 Jul 2024 23:54:12 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20nginx-prometheus-exporter=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose-deploy.yml | 11 +++++++++++ monitoring/prometheus/prometheus.yml | 4 ++++ nginx/configs/nginx-blue.conf | 13 +++++++++++++ nginx/configs/nginx-green.conf | 13 +++++++++++++ nginx/nginx.conf | 13 +++++++++++++ 5 files changed, 54 insertions(+) diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index e78fca1..a4876d3 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -130,9 +130,20 @@ services: - ./nginx/configs:/etc/nginx/configs ports: - "80:80" + - "8" restart: always networks: - teamhnet + nginx-prometheus-exporter: + container_name: nginx-prometheus-exporter + image: nginx/nginx-prometheus-exporter:1.3 + environment: + - SCRAPE_URI=http://nginx:9110/metrics + ports: + - "9113:9113" + networks: + - teamhnet + networks: teamhnet: \ No newline at end of file diff --git a/monitoring/prometheus/prometheus.yml b/monitoring/prometheus/prometheus.yml index 1d439cd..fbf63a8 100644 --- a/monitoring/prometheus/prometheus.yml +++ b/monitoring/prometheus/prometheus.yml @@ -11,3 +11,7 @@ scrape_configs: static_configs: - targets: ['cadvisor:8080'] + - job_name: 'nginx' + static_configs: + - targets: ['nginx-prometheus-exporter:9113'] + diff --git a/nginx/configs/nginx-blue.conf b/nginx/configs/nginx-blue.conf index f059dc6..c783791 100644 --- a/nginx/configs/nginx-blue.conf +++ b/nginx/configs/nginx-blue.conf @@ -51,4 +51,17 @@ http { } + # nginx prometheus exporter를 위한 설정 + server { + # 내부적으로 사용하기 위해 9110 포트로 설정 + listen 9110; + server_name localhost; + + location /metrics { + stub_status on; # stub_status 활성화 + allow all; # allow 접근을 허용할 주소 설정 + # deny 접근을 허용하지 않을 주소 설정 + } + } + } \ No newline at end of file diff --git a/nginx/configs/nginx-green.conf b/nginx/configs/nginx-green.conf index 05ceb6b..2d62eee 100644 --- a/nginx/configs/nginx-green.conf +++ b/nginx/configs/nginx-green.conf @@ -52,4 +52,17 @@ http { } + # nginx prometheus exporter를 위한 설정 + server { + # 내부적으로 사용하기 위해 9110 포트로 설정 + listen 9110; + server_name localhost; + + location /metrics { + stub_status on; # stub_status 활성화 + allow all; # allow 접근을 허용할 주소 설정 + # deny 접근을 허용하지 않을 주소 설정 + } + } + } \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index f60dd0f..8541c3e 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -53,4 +53,17 @@ http { } + # nginx prometheus exporter를 위한 설정 + server { + # 내부적으로 사용하기 위해 9110 포트로 설정 + listen 9110; + server_name localhost; + + location /metrics { + stub_status on; # stub_status 활성화 + allow all; # allow 접근을 허용할 주소 설정 + # deny 접근을 허용하지 않을 주소 설정 + } + } + } \ No newline at end of file From e306c40224cae7f6cc2321b3454511567398aed9 Mon Sep 17 00:00:00 2001 From: kalsteve Date: Sun, 28 Jul 2024 23:57:46 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20nginx=20docker=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index a4876d3..2b1b109 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -130,7 +130,6 @@ services: - ./nginx/configs:/etc/nginx/configs ports: - "80:80" - - "8" restart: always networks: - teamhnet From aa2b6c4e5d6c02d864993b47911b8f7150f96a5d Mon Sep 17 00:00:00 2001 From: kalsteve Date: Mon, 29 Jul 2024 18:11:16 +0900 Subject: [PATCH 3/6] fix: cors error --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 9992200..77a9872 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,6 @@ import app.config.envSetting # 환경 변수를 가져오기 위한 설정 -from fastapi import FastAPI ,Request -from starlette.middleware.cors import CORSMiddleware +from fastapi import FastAPI, Request +from fastapi.middleware.cors import CORSMiddleware from prometheus_fastapi_instrumentator import Instrumentator import logging @@ -21,7 +21,7 @@ # CORS 설정 app.add_middleware( CORSMiddleware, - allow_origins=["http://localhost:5173", "https://brain-washer.net/"], # 모든 도메인에서의 요청을 허용 + allow_origins=["http://localhost:5173", "https://brain-washer.net"], # 모든 도메인에서의 요청을 허용 allow_credentials=True, allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], # 허용할 메서드들 설정 allow_headers=["*"], # 모든 헤더를 허용 From 70d18ac797940edc374d284cab3268133be84165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=99=8D=EC=84=9D?= Date: Mon, 29 Jul 2024 21:11:30 +0900 Subject: [PATCH 4/6] #59: WIP on feat/#59 --- monitoring/prometheus/prometheus.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitoring/prometheus/prometheus.yml b/monitoring/prometheus/prometheus.yml index 1d439cd..a6374c9 100644 --- a/monitoring/prometheus/prometheus.yml +++ b/monitoring/prometheus/prometheus.yml @@ -11,3 +11,5 @@ scrape_configs: static_configs: - targets: ['cadvisor:8080'] + + From 257eca9585e77a59221bc7b258952f02c64ec338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=99=8D=EC=84=9D?= Date: Mon, 29 Jul 2024 21:22:20 +0900 Subject: [PATCH 5/6] =?UTF-8?q?bug:=EC=95=A4=EB=93=9C=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=AA=A8=EB=8B=88?= =?UTF-8?q?=ED=84=B0=EB=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routers/images.py | 2 +- app/routers/voices.py | 2 +- monitoring/elk/filebeat/filebeat.yml | 2 +- monitoring/elk/logstash/logstash.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/routers/images.py b/app/routers/images.py index c7e9d1d..f3dbe5f 100644 --- a/app/routers/images.py +++ b/app/routers/images.py @@ -88,7 +88,7 @@ def read_samples(character_name: str, db: Session = Depends(get_db)): # 이미지 다운로드 수 -@router.post("/download_count/{image_id}", response_model=ResultResponseModel, summary="이미지 다운로드 수", +@router.post("/downloadcount/{image_id}", response_model=ResultResponseModel, summary="이미지 다운로드 수", description="이미지 다운로드 수를 알려줍니다.") def download_image_count(image_id: int, db: Session = Depends(get_db)): image = image_service.get_image(db, image_id=image_id) diff --git a/app/routers/voices.py b/app/routers/voices.py index c9a917e..f3aa2c1 100644 --- a/app/routers/voices.py +++ b/app/routers/voices.py @@ -81,7 +81,7 @@ def hard_delete_voice(voice_id: int, db: Session = Depends(get_db)): #목소리 다운로드 수 -@router.post("/download_count/{voice_id}", response_model=ResultResponseModel, summary="목소리 다운로드 수", +@router.post("/downloadcount/{voice_id}", response_model=ResultResponseModel, summary="목소리 다운로드 수", description="목소리 다운로드 수를 알려줍니다") def download_voice_count(voice_id: int, db: Session = Depends(get_db)): voice = voice_service.get_voice(db, voice_id=voice_id) diff --git a/monitoring/elk/filebeat/filebeat.yml b/monitoring/elk/filebeat/filebeat.yml index 451b14b..693bfc4 100644 --- a/monitoring/elk/filebeat/filebeat.yml +++ b/monitoring/elk/filebeat/filebeat.yml @@ -7,4 +7,4 @@ filebeat.inputs: output.logstash: hosts: ["logstash:5044"] -logging.level: error \ No newline at end of file +logging.level: info \ No newline at end of file diff --git a/monitoring/elk/logstash/logstash.yml b/monitoring/elk/logstash/logstash.yml index 2ed3df8..07b96cc 100644 --- a/monitoring/elk/logstash/logstash.yml +++ b/monitoring/elk/logstash/logstash.yml @@ -1,3 +1,3 @@ http.host: "0.0.0.0" # 모든 인터페이스에서 수신 대기 -log.level: error # 로그 레벨 설정 +log.level: info # 로그 레벨 설정 path.logs: /var/log/logstash #저장할 위치 \ No newline at end of file From e1770b2dc81056de7e69ecb15ff5c7551b4211b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=99=8D=EC=84=9D?= Date: Mon, 29 Jul 2024 21:42:56 +0900 Subject: [PATCH 6/6] bug:download --- app/routers/images.py | 2 +- app/routers/voices.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/routers/images.py b/app/routers/images.py index f3dbe5f..e6b95ab 100644 --- a/app/routers/images.py +++ b/app/routers/images.py @@ -88,7 +88,7 @@ def read_samples(character_name: str, db: Session = Depends(get_db)): # 이미지 다운로드 수 -@router.post("/downloadcount/{image_id}", response_model=ResultResponseModel, summary="이미지 다운로드 수", +@router.post("/count/{image_id}", response_model=ResultResponseModel, summary="이미지 다운로드 수", description="이미지 다운로드 수를 알려줍니다.") def download_image_count(image_id: int, db: Session = Depends(get_db)): image = image_service.get_image(db, image_id=image_id) diff --git a/app/routers/voices.py b/app/routers/voices.py index f3aa2c1..b7d35d8 100644 --- a/app/routers/voices.py +++ b/app/routers/voices.py @@ -81,7 +81,7 @@ def hard_delete_voice(voice_id: int, db: Session = Depends(get_db)): #목소리 다운로드 수 -@router.post("/downloadcount/{voice_id}", response_model=ResultResponseModel, summary="목소리 다운로드 수", +@router.post("/count/{voice_id}", response_model=ResultResponseModel, summary="목소리 다운로드 수", description="목소리 다운로드 수를 알려줍니다") def download_voice_count(voice_id: int, db: Session = Depends(get_db)): voice = voice_service.get_voice(db, voice_id=voice_id)