Skip to content

Commit

Permalink
build: Grafana + Prometheus + nodeexporter를 통한 리소스 모니터링
Browse files Browse the repository at this point in the history
  • Loading branch information
sejokim committed Mar 10, 2024
1 parent dbc2389 commit 756f393
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ django-debug-toolbar==4.2.0
django-environ==0.11.2
djangorestframework==3.14.0
djangorestframework-simplejwt==5.3.1
django-prometheus==2.3.1
prometheus_client==0.20.0
drf-yasg==1.21.7
hvac==2.1.0
idna==3.6
Expand Down
3 changes: 3 additions & 0 deletions backend/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def wait_for_vault_client(client, retries=5, delay=5):
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'django_prometheus',
]

ELASTICSEARCH_DSL = {
Expand All @@ -199,6 +200,7 @@ def wait_for_vault_client(client, retries=5, delay=5):
REST_USE_JWT = True

MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -208,6 +210,7 @@ def wait_for_vault_client(client, retries=5, delay=5):
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
]

ROOT_URLCONF = 'src.urls'
Expand Down
17 changes: 1 addition & 16 deletions backend/src/urls.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
"""
URL configuration for src project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path, re_path
from django.conf import settings
Expand All @@ -40,6 +24,7 @@
path('api/', include('api.urls')),
re_path(r'^redoc/$', schema_view.with_ui('redoc',
cache_timeout=0), name='schema-redoc'),
path('', include('django_prometheus.urls')),
]

# DEBUG 모드일 경우, ui 없이 swagger view를 사용할 수 있도록 설정
Expand Down
53 changes: 53 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,59 @@ services:
# networks:
# - app_network

# node_exporter:
# image: prom/node-exporter
# container_name: node_exporter_container
# ports:
# - 9100:9100
# volumes:
# - "/proc:/host/proc"
# - "/sys:/host/sys"
# - "/:/rootfs"
# - "/etc:/host/etc:ro"
# - "${CERTS_PATH}:/etc/ssl/certs"
# - "${PROMETHEUS_CONFIG}:/etc/node_exporter"
# command:
# - '--path.procfs=/host/proc'
# - '--path.sysfs=/host/sys'
# - '--path.rootfs=/rootfs'
# - '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)'
# - '--web.config.file=/etc/node_exporter/web.yml'
# networks:
# - app_network

# prometheus:
# build:
# context: ./prometheus
# dockerfile: Dockerfile
# container_name: prometheus_container
# env_file:
# - .env
# volumes:
# - "${PROMETHEUS_DATA}:/prometheus/data"
# - "${PROMETHEUS_CONFIG}:/prometheus/config"
# - "${CERTS_PATH}:/etc/ssl/certs"
# ports:
# - 9090:9090
# networks:
# - app_network

# grafana:
# build:
# context: ./grafana
# dockerfile: Dockerfile
# container_name: grafana_container
# env_file:
# - .env
# volumes:
# - "${GRAFANA_DATA}:/var/lib/grafana"
# - "${GRAFANA_CONFIG}:/etc/grafana/grafana.ini"
# - "${CERTS_PATH}:/etc/ssl/certs"
# ports:
# - 3000:3000
# networks:
# - app_network

volumes:
static-volume:
cert-volume:
Expand Down
1 change: 1 addition & 0 deletions grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM grafana/grafana:latest
2 changes: 1 addition & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN chmod +x /usr/local/bin/mkcert

RUN mkcert -install
RUN mkdir -p /etc/nginx/certs
RUN mkcert -key-file /etc/nginx/certs/server.key -cert-file /etc/nginx/certs/server.crt "hashicorp_vault" localhost 127.0.0.1 ::1
RUN mkcert -key-file /etc/nginx/certs/server.key -cert-file /etc/nginx/certs/server.crt "hashicorp_vault" "django_node_app" "prometheus" "grafana" "alertmanager" localhost 127.0.0.1 ::1

# Nginx 설정 파일 복사 및 모듈 로드
COPY ./config/nginx.conf /etc/nginx/nginx.conf
Expand Down
4 changes: 4 additions & 0 deletions prometheus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM prom/prometheus:latest


CMD ["--config.file=/prometheus/config/prometheus.yml", "--web.config.file=/prometheus/config/web.yml", "--web.enable-lifecycle"]

0 comments on commit 756f393

Please sign in to comment.