๐บ ๋ชฉ์ฐจ ๐บ(๋ณด์๋ ค๋ฉด ์๋ ๋๋ณด๊ธฐ ๋ฅผ ๋๋ฌ์ฃผ์ธ์.)
1. ์ค์นํ ๊ฒ๋ค
๊ฐ. nodeexporter : ์๋ฒ ๋ฐ ๋คํธ์ํฌ ์ ๋ณด ๋ฑ ์์คํ metric ๋ฐ์ดํฐ๋ฅผ ์์งํ์ฌ ์ ๊ณต
๋. cadvisor : ์ปจํ ์ด๋๋ค์ ์ ๋ณด ๋ฐ์ดํฐ๋ฅผ ์์งํ์ฌ ์ ๊ณต
๋ค. prometheus : ๋ชจ๋ํฐ๋ง ๋์์ metric ๋ฐ์ดํฐ๋ฅผ ์์ง
๋ผ. alertmanager : prometheus์์ ์์ฑ๋ ๊ฒฝ๊ณ ๋ฅผ ์์ ๋์ ์ผ๋ก ๋ผ์ฐํ
๋ง. grafana : ๋ฉํธ๋ฆญ ๋ฐ์ดํฐ๋ฅผ ์ฐจํธ, ๊ทธ๋ํ ๋ฑ์ผ๋ก ์๊ฐํํด์ ๋ณด์ฌ์ฃผ๋ ๋๊ตฌ
2. ํ์ผ ์์
๊ฐ. docker-dompose.yml ์์
### ์ ๋ถ๋ถ ๋์ผ ###
services:
front_nginx:
container_name: front_nginx_cname
image: mungkhs/nginxwaf:1.1 #DockerHub์ ์ฌ๋ ค์ง ์ฐ๋ฆฌ์ ์ด๋ฏธ์ง๋ฅผ ์ด์ฉํจ.
restart: always
privileged: true
ports:
- "80:80"
- "81:81"
- "82:82"
- "8685:8685" #vnstat
#- "19999:19999" #netdata๋ ์ฃผ์ ์ฒ๋ฆฌ ํ ๊ฒ
- "3000:3000" #๐ดgrafana ํฌํธ ์ถ๊ฐ
### ์ค๊ฐ ๋ถ๋ถ ๋์ผ ###
### ์ด์ ๊ฒ์๊ธ์ netdata ๋ถ๋ถ์ ์ฃผ์ ์ฒ๋ฆฌ(์ญ์ )ํ๊ธฐ ###
### ์๋ ๋ถ๋ถ ์ถ๊ฐ ###
prometheus:
image: prom/prometheus:v2.40.2
container_name: prometheus
user: root
volumes:
- ./prom/prometheus:/etc/prometheus
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=200h'
- '--web.enable-lifecycle'
restart: unless-stopped
depends_on:
- cadvisor
expose:
- 9090
#ports:
# - 9090:9090
networks:
- mung_net
alertmanager:
image: prom/alertmanager:v0.24.0
container_name: alertmanager
volumes:
- ./prom/alertmanager:/etc/alertmanager
command:
- '--config.file=/etc/alertmanager/config.yml'
- '--storage.path=/alertmanager'
restart: unless-stopped
expose:
- 9093
networks:
- mung_net
nodeexporter:
image: prom/node-exporter:v1.4.0
container_name: nodeexporter
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)'
restart: unless-stopped
expose:
- 9100
networks:
- mung_net
cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.46.0
container_name: cadvisor
privileged: true
command:
- '-housekeeping_interval=10s'
- '-docker_only=true'
devices:
- /dev/kmsg:/dev/kmsg
security_opt:
- no-new-privileges:true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker:/var/lib/docker:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /sys/fs/cgroup:/cgroup:ro
- /dev/disk/:/dev/disk:ro
restart: unless-stopped
expose:
- 8080
networks:
- mung_net
grafana:
image: grafana/grafana:9.2.5
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana
- ./prom/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SECURITY_ADMIN_USER=admin #๐ดgrafana ๋ก๊ทธ์ธ ์์ด๋ ์ค์
- GF_SECURITY_ADMIN_PASSWORD=password #๐ดgrafana ๋ก๊ทธ์ธ ํจ์ค์๋ ์ค์
- GF_USERS_ALLOW_SIGN_UP=false
restart: unless-stopped
depends_on:
- cadvisor
- prometheus
expose:
- 3000
#ports:
# - 3000:3000
networks:
- mung_net
volumes:
vnstatdb:
prometheus_data: #๐ด์ถ๊ฐ
grafana_data: #๐ด์ถ๊ฐ
๋. docker/front/default.conf ํ์ผ์ ์๋ ๋ด์ฉ ์ถ๊ฐ
### ์ด์ ์ ์ถ๊ฐํ๋ netdata ๋ถ๋ถ์ ์ฃผ์ ์ฒ๋ฆฌํ๊ธฐ
server {
listen 3000;
location / {
proxy_pass http://grafana:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
๐ด ๋ฐฉํ๋ฒฝ์์ 3000 ํฌํธ ์ด์ด์ฃผ๊ธฐ
3. ๊ฐ์ข ํ๋ก๊ทธ๋จ๋ค ์ค์ ํ์ผ๋ค ์์
ํด๋ ๋ฐ ํ์ผ๋ค์ ์์ค ํ์ผ๋ค์ ๋ค์ด๋ฐ์ ์ฐธ๊ณ ํ์ธ์.
๊ฐ. prom/alertmanager/config.yml ํ์ผ ์์
์ด๋ ๊ฒ ์ค์ ํด๋๋ฉด ์๋ฒ์ ๋ฌธ์ ๊ฐ ๋ฐ์์ ์ด๋ฉ์ผ๋ก ๋ด์ฉ์ด ๋ฐ๋ก ์ ์ก๋ฉ๋๋ค.
route:
receiver: email-alert
receivers:
- name: email-alert
email_configs: ## ์ฌ๊ธฐ์๋ ์ง๋ฉ์ผ์ ์์๋ก ํจ
- to: ์์ด๋@gmail.com ## ๋ฐ์ ๋ฉ์ผ ์ฃผ์
from: ์์ด๋@gmail.com ## ๋ณด๋ผ ๋ฉ์ผ ์ฃผ์
smarthost: smtp.gmail.com:587 ## gmail smtp ์ฃผ์
auth_username: ์์ด๋@gmail.com ## gmail ์ฌ์ฉ์ ์ ๋ณด
auth_identity: ์์ด๋@gmail.com ## gmail ์ฌ์ฉ์ ์ ๋ณด
auth_password: bsy************* ## 1๏ธโฃ ์ฑ ๋น๋ฐ๋ฒํธ
send_resolved: true
์ 1๏ธโฃ๋ฒ ๋ถ๋ถ ์ฑ ๋น๋ฐ๋ฒํธ ๋ฐ๊ธ ๋ฐฉ๋ฒ์ ์๋ ๊ฒ์๊ธ์ ์ฐธ๊ณ ํด ๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
https://hyunmin1906.tistory.com/276
๋. prom\prometheus\alert.rules ์์
groups:
- name: targets
rules:
- alert: monitor_service_down
expr: up == 0
for: 30s
labels:
severity: critical
annotations: ##๐ด์ํ๋ ๋๋ก ์๋ ๋ฉ์์ง ์์
summary: "mungssem Monitor service non-operational"
description: "mungssem Service {{ $labels.instance }} is down."
- name: host
rules:
- alert: high_cpu_load1
expr: node_load1 > 60 ##๐ด์ํ๋ ๊ฐ์ผ๋ก ์์
for: 30s
labels:
severity: warning
annotations: ##๐ด์ํ๋ ๋๋ก ์๋ ๋ฉ์์ง ์์
summary: "mungssem Server under high load"
description: "mungssem Docker host is under high load, the avg load 1m is at {{ $value}}. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."
- alert: high_memory_load
expr: (sum(node_memory_MemTotal_bytes) - sum(node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes) ) / sum(node_memory_MemTotal_bytes) * 100 > 85
for: 30s
labels:
severity: warning
annotations: ##๐ด์ํ๋ ๋๋ก ์๋ ๋ฉ์์ง ์์
summary: "mungssem Server memory is almost full"
description: "mungssem Docker host memory usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."
- alert: high_storage_load
expr: (node_filesystem_size_bytes{fstype="aufs"} - node_filesystem_free_bytes{fstype="aufs"}) / node_filesystem_size_bytes{fstype="aufs"} * 100 > 85
for: 30s
labels:
severity: warning
annotations: ##๐ด์ํ๋ ๋๋ก ์๋ ๋ฉ์์ง ์์
summary: "mungssem Server storage is almost full"
description: "mungssem Docker host storage usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."
- name: containers
rules:
- alert: container_down
expr: | ##๐ด์๋ ์ปจํ
์ด๋๋ช
๋ค์ ์์ ์ ๋ง๊ฒ ์์
(absent(container_memory_usage_bytes{name="front_nginx_cname"})
or absent(container_memory_usage_bytes{name="nginx_cname"})
or absent(container_memory_usage_bytes{name="nginx_cname2"})
or absent(container_memory_usage_bytes{name="php_cname"})
or absent(container_memory_usage_bytes{name="php2_cname"})
or absent(container_memory_usage_bytes{name="mysql_cname"})
or absent(container_memory_usage_bytes{name="phpmyadmin_cname"})
)
for: 1m
labels:
severity: critical
annotations: ##๐ด์ํ๋ ๋๋ก ์๋ ๋ฉ์์ง ์์
summary: "mungssem Container '{{ $labels.name }}' down"
description: "mungssem container with name '{{ $labels.name }}' is down for more than one minute in main VM"
๋ค. ๊ทธ์ธ์ ์ค์ ํ์ผ๋ค์ ๊ทธ๋๋ก ์ฌ์ฉํจ. ๋จ, ์ปจํ ์ด๋๋ช ์ ์์ ๋ค๋ฅด๊ฒ ์์ฑํ ๊ฒฝ์ฐ ๊ฐ๊ฐ์ ์ค์ ํ์ผ๋ค์ ์์ ํด ์ฃผ์ด์ผ ํจ.
4. grafana ์คํ ํ๋ฉด
๊ฐ. ์ฐ์ ์ปจํ ์ด๋๋ฅผ ์์ฑํ ํ http://์๋ฒ์์ดํผ:3000 ์ผ๋ก ์ ์ํฉ๋๋ค.
๋. docker-compose.yml์์ ์ค์ ํ ์์ด๋, ํจ์ค์๋๋ฅผ ์ ๋ ฅ ํ ๋ก๊ทธ์ธ ํ ํ, ์๋์ ๊ฐ์ด ์์๋๋ก ๋๋ฌ์ค๋๋ค.
๋ค. ๊ทธ๋ผ ์๋์ ๊ฐ์ด ์๋ฒ, ์ปจํ ์ด๋ ๋ค์ ์ ๋ณด๋ค์ ๋ณผ ์ ์์ต๋๋ค.
5. ๊ฒฝ๊ณ ๋ฉ์ผ ์์
์ alertmanager ์ค์ ์์ ๊ฒฝ๊ณ ๋ฉ์ผ ๋ฐ์ ๊ณณ์ ์ง๋ฉ์ผ๋ก ํด๋์์ต๋๋ค. ๋ฐ๋ผ์, ์๋ฒ์ ๊ฒฝ๊ณ ์ํฉ์ด ๋ฐ์๋๋ฉด ์๋์ ๊ฐ์ด ๋ฉ์ผ์ด ๋ฐ๋ก ๋ ์์ค๊ฒ ๋ฉ๋๋ค.
๐บ๐บ ์์ ํ ๋ชจ๋ ์์ค๋ ์๋ ๋งํฌ์์ ํ์ธํ์ค ์ ์์ต๋๋ค. ๐บ๐บ
https://github.com/mmssem/ServerMonitoring
GitHub - mmssem/ServerMonitoring
Contribute to mmssem/ServerMonitoring development by creating an account on GitHub.
github.com