basic
source-code : https://github.com/teamsmiley/devops-public/tree/main/monitoring/2.grafana-provisioning
์๋ฒ๋ ํ๋ก๊ทธ๋จ์ ๋ชจ๋ํฐ๋ง ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
ํน์ง์ pull๋ฐฉ์์ด๋ผ๋๊ฒ. ์ด๊ฒ์ด ์ ์ ํ์
Prometheus ์๋ฒ๊ฐ ๋ ธ๋์ ๋ฐ์ดํฐ๋ฅผ ์์ฒญํ๋ฉด ๋ ธ๋๋ ํ๋ก๊ทธ๋จ๋ฑ์ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด์ฃผ๋ฉด ๋๋ค. ๋ ธ๋๋ ์ ํ prometheus ์๋ฒ์ ๋ํด ์ ํ์๊ฐ ์๊ณ ๋ฐ์ดํฐ์ ์ ๋ฌ์ ๋ํด์ ๊ณ ๋ฏผํ์ง ์์๋ ๋๋ค.
push : ๊ฐ๊ฐ ๋ชจ๋ํฐ๋๋ ์๋ฒ์์ ์ฃผ๊ธฐ์ ์ผ๋ก ๋ชจ๋ํฐ๋ง ์๋ฒ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด๋ ๋ฐฉ์
pull : ๊ฐ๊ฐ ๋ชจ๋ํฐ๋๋ ์๋ฒ์์ ๋ฐ๋ชฌ๋ง ๋๊ณ ์๊ณ ๋ชจ๋ํฐ๋ง ์๋ฒ์์ request๋ฅผ ๋์ ์ pullํ๋ ๋ฐฉ์
๊ตฌ์ฑ
prometheus : ๋ฐ์ดํฐ๋ฅผ ์์ฒญํ๊ณ ๊ฐ์ ธ์จ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ณ ์ฟผ๋ฆฌํจ
exporter: ์์ฒญ์ ๋ฐ์ผ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด์ ์์ฒญ์์๊ฒ ๋ฆฌํดํด ์ค๋ค.
push gateway : ๋ฐ๋ชฌํํ๋ก ํ๋ก๊ทธ๋จ์ด ๋ ์๋๊ฒ ์๋๊ณ ๋ฐฐ์นํํ๋ก ์คํ๋๊ณ ์ฌ๋ผ์ง๋ ํ๋ก์ธ์ค๋ pull์ ํ ์๊ฐ ์์ผ๋ฏ๋ก ์ด๊ฑธ ์ด์ฉํด์ prometheus์ ๋ณด๋ด์ค๋ค.
alarm manager : ๋ฐ์ดํฐ๊ฐ ํน์ ์กฐ๊ฑด์ด ๋๋ฉด ์๋ฆผ์ ์๋ ค์ค๋ค. (์ฌ๋ ๋๋ ์ด๋ฉ์ผ ๋ฑ๋ฑ ๋ง๋ค.)
dashboard : ์นํ๋ฉด์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ค๋ค. ๊ธฐ๋ณธ์ ์ธ ํ๋ฉด์ด prometheus๊ฐ ๊ฐ์ง๊ณ ์์ผ๋ Grafana๋ฅผ ๋๋ถ๋ถ ์ฌ์ฉํ๋ค.
๋ชจ๋ํฐ๋งํ ๋
ธ๋ ์ค์ ์ถ๊ฐ
https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus.yml
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
prometheus.yml์ ์ค์ ํ๊ณ ๋์ ๋์ปค๋ฅผ ์คํํ์.
docker-compose up -d
์๋น์ค๊ฐ ์คํ๋๋ฉด ๋ก์ปฌ์์ ํ์ธํด๋ณด์
์ด์ ์น๋ธ๋ผ์ฐ์ ๋ฅผ ํตํด http://localhost:9090 ์ ํ์ธํด๋ณด๋ฉด ์์ ์๋ค.

์ด์ ํ์ธํด๋ณด์.
๋ค์๊ทธ๋ฆผ์ฒ๋ผ up์ ๋ฃ๊ณ ์ํฐ๋ฅผ ์ฒ๋ณด๋ฉด

up์ Prometheus๊ฐ ์ถ๊ฐํ๋ ํน๋ณํ ํํ์ ๋ฉํธ๋ฆญ์ด๋ค. 1์ ์ฑ๊ณต์ด๋ผ๋ ์๋ฏธ์ด๋ค.
๋ชจ๋ํฐ๋ง ํ๊ธฐ
Node Exporter ์ค์น (linux)
์ด์ ๋ชจ๋ํฐ๋ง ํ ์๋ฒ๋ฅผ ์ค์ ํ์. Prometheus๊ฐ ์์ฒญํ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด์ ์ค๋ค.
Node Exporter๋ cpu ๋ฉ๋ชจ๋ฆฌ ๋์คํฌ๊ณต๊ฐ ๋์คํฌ i/o ๋คํธ์ํฌ ๋์ญํญ ๊ฐ์ ๋ชจ๋ ํ์ค ๋ฉํธ๋ฆญ์ ์ ๊ณตํ๋ค.
๋ ธ๋ exporter๋ ๋ฐ์ด๋๋ฆฌ๋ก ์ค์น
https://prometheus.io/download
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar -xvzf node_exporter-0.18.1.linux-amd64.tar.gz
cd node_exporter-0.18.1.linux-amd64/
mv node_exporter /usr/local/bin/
vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter
๋ชจ๋ํฐ๋ง ๋นํ๋ ์๋ฒ์ ๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์๋ณด์.
http://192.168.0.101:9100/metrics
๊ฒฐ๊ณผ๊ฐ ์ญ ๋์จ๋ค node exporter๋ ๋์ํ๋ค. ์ด์ ํ๋ก๋ฉํ ์ฐ์ค๊ฐ ์ฃผ๊ธฐ์ ์ผ๋ก ์ด๊ฑธ ๊ฐ์ ธ์ค๋ฉด๋๋ค.
Prometheus ์ค์ ์ ์ถ๊ฐํ์.
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['192.168.0.101:9100']
# - targets: ['192.168.0.101:9100','192.168.0.102:9100'] #์ฌ๋ฌ๋๋ฉด ์ด๋ ๊ฒ ์ถ๊ฐํ๋ฉด๋๋ค.
Prometheus ํ๊ฒ์ ์ถ๊ฐ๊ฐ ๋๊ฑด์ง ํ์ธํ์.
node01์์ ์ฌ๋ถํ ํด๋ณด์ ์๋น์ค๋ง ๊บผ๋ ๋จ.
ssh node01
systemctl stop node_exporter
systemctl status node_exporter
systemctl start node_exporter
systemctl status node_exporter
์ด์ http://localhost:9090/graph ์์ up์ ํ์ธํด๋ณด์ ๋ด๋ ค๊ฐ๋ค๊ฐ ์ฌ๋ผ์จ๊ฒ์ ํ์ธํ ์ ์๋ค.

Prometheus ์ ๋์ํ๊ณ node exporter๋ ์ ๋์ํ๋๊ฒ์ ์์๊ฐ ์๋ค.
์ด์ docker-compose๋ก ๋ง๋ค์ด์๋ณด์.
version: '3.7'
services:
localhost:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- 9090:9090
restart: always
volumes:
prometheus_data: {}
docker-compose up -d
์๋์ฐ node ๋ชจ๋ํฐ๋ง
์ฐธ๊ณ https://medium.com/@facundofarias/setting-up-a-prometheus-exporter-on-windows-b3e45f1235a5
https://github.com/martinlindhe/wmi_exporter
https://grafana.com/grafana/dashboards/2129 theme
https://github.com/martinlindhe/wmi_exporter/releases ๋ค์ดํ ์ค์นํ๋ฉด ์๋น์ค๋ก ์ค์น ์๋ฃ

msi downloadํ ๋ ธ๋์ ์ค์น
์ค์น ๋ ธ๋์์ ๋ค์ ํ์ธ
์ธ๋ถ์์ ๋ค์ ํ ์คํธ
Prometheus์ ์ถ๊ฐํ์ฌ ๋ถ์ด์. 9182 ํฌํธ๋ฅผ ์ด๋ค.
vi prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
---
- job_name: 'win_node_exporter'
static_configs:
- targets: ['10.1.5.40:9182', '10.1.5.57:9182']
์ด๋ ๊ฒ ํ๋ฉด ์๋์ฐ๋ ๋ชจ๋ํฐ๋ง์ด ๋๋ค.
์๋ฆผ
node export node01์๊บผ๋ณด์.
ssh node01 systemctl stop node_exporter
http://localhost:9090/targets ์์ ์ฒดํฌํด๋ณด๋ฉด ๊บผ์ง๊ฒ์ ์์ ์๋ค.
๊ทธ๋ํ์์ up == 0 ์ ๋ฃ์ด์ ๊บผ์ง๊ฒ๋ง ํ์ธํด๋ณด์.
1๊ฐ๋ง ๋์จ๋ค.

์ด์ ๋ค ๋๋ฏ
์๋ฆผ ๊ท์น ์ถ๊ฐ
vi /data/git/docker/prometheus/prometheus.yml
global:
...
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
rule_files:
- "rules.yml"
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
vi rules.yml
groups:
- name: example
rules:
- alert:InstanceDown
expr: up == 0
for: 1m
docker run -d -p 9090:9090 -v /data/git/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/git/docker/prometheus/rules.yml:/etc/prometheus/rules.yml --name prom prom/prometheus
http://localhost:9090/alerts

์ด์ ์๋ฆผ์ด ํ๋ณด๊ฐ ๋ฌ๋ค.
์๋ ๋งค๋์ ์ค์น
๋ฐ์ด๋๋ฆฌ์ ๋์ปค๋ก ์ฌ๋ฆฌ๋ ๋ฐฉ์ 2๊ฐ์ง๊ฐ ์๋ค. ๋์ปค๋ฅผ ์ฌ์ฉํ๋ค.
ssh prometheus
https://github.com/prometheus/alertmanager/blob/master/doc/examples/simple.yml ์ฐธ๊ณ
vi alertmanager.yml
global:
smtp_smarthost: 'localhost:25'
smtp_from: 'alertmanager@example.org'
route:
receiver: team-mails
receivers:
- name: 'team-mails'
email_configs:
- to: 'teamsmiley@gmail.com'
docker run -p 9090:9090 -v /data/git/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/git/docker/prometheus/rules.yml:/etc/prometheus/rules.yml -v /data/git/docker/prometheus/alertmanager.yml:/etc/prometheus/alertmanager.yml prom/prometheus
./alertmanager๋ฅผ ์คํํ๋ฉด ์ด๋ฉ์ผ์ ๋ฐ๋๋ค.
Last updated
Was this helpful?