โ๏ธ ์ด ๊ธ์์ ์งํํ ๊ฒ๋ค
1. Redis ์ค์น
2. Node Exporter ์ค์น
3. Redis Exporter ์ค์น
4. Prometheus ์ค์น
5. Prometheus์ Exporter ์ฐ๊ฒฐ
6. Grafana ์ค์น
7. Grafana์ Prometheus ์ฐ๊ฒฐ
8. Grafana์ ๋์๋ณด๋ ์์ฑ
9. Alertmanager ์ค์น ๋ฐ Dooray! ์ธ์ปค๋ฐ ํ ์๋ฆผ ์ค์
monitored ์ธ์คํด์ค์ node exporter์ ์ค์นํ redis ๋ฒ์ ๋ณ๋ก redis exporter๋ฅผ ์ค์นํฉ๋๋ค.
monitoring ์ธ์คํด์ค์ prometheus๋ฅผ ์ค์นํ๊ณ exporter๋ค์ ์ฐ๊ฒฐํฉ๋๋ค.
monitoring ์ธ์คํด์ค์ grafana๋ฅผ ์ค์นํ๊ณ prometheus๋ฅผ ์ฐ๊ฒฐํด์ฃผ๋ฉด, ์ต์ข ์ ์ผ๋ก exporter์์ ์์ง๋๋ ๋ฉํธ๋ฆญ์ ์๊ฐํํด์ grafana๋ก ํ์ธํ ์ ์์ต๋๋ค.
์ด ๊ณผ์ ์ ์๋์์ ํ๋์ฉ ์งํํด๋ณด๊ฒ ์ต๋๋ค :)
์ค์น ํ๊ฒฝ
- NHN Cloud
- CentOS 7.9
- Redis 6.2.9, 7.0.11
- Node Exporter 1.5.0
- Redis Exporter
- Prometheus 2.44.0
- Grafana Enterprise 9.5.2
- Alertmanager 0.25.0
๊ตฌ์ฑ๋
- Redis Server์ Node Exporter์ ์ค์นํ Redis ๋ฒ์ ๋ณ๋ก Redis Exporter๋ฅผ ์ค์นํฉ๋๋ค.
- Monitoring Server์ Prometheus๋ฅผ ์ค์นํ๊ณ , Exporter๋ค์ ์ฐ๊ฒฐํฉ๋๋ค.
- Monitoring Server์ Grafana๋ฅผ ์ค์นํ๊ณ , Prometheus๋ฅผ ์ฐ๊ฒฐํฉ๋๋ค.
- ์ต์ข ์ ์ผ๋ก Exporter์์ ์์ง๋๋ ๋ฉํธ๋ฆญ์ ์๊ฐํํด์ Grafana๋ก ํ์ธํ ์ ์์ต๋๋ค.
Node Exporter
NIX ์ปค๋์ ์ํด ๋์ถ๋ ํ๋์จ์ด ๋ฐ OS ๋ฉํธ๋ฆญ์ค ๋ผ๊ณ ํ๋๋ฐ.. ์ฝ๊ฒ ์ค๋ช ํ์๋ฉด ์คํ์ด์ ๊ฐ๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค.
Node Exporter๋ ์ฐ๋ฆฌ๊ฐ ๋ชจ๋ํฐ๋ง ํ๋ ค๋ ์๋ฒ์ ์ค์น๋์ด ํด๋น ์๋ฒ์ ๋ฉํธ๋ฆญ๋ค์ ์์งํฉ๋๋ค.
โ ๊ณต์ ๋ฌธ์
https://prometheus.io/docs/guides/node-exporter/
Monitoring Linux host metrics with the Node Exporter | Prometheus
An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
prometheus.io
โ ๊ณต์ Github
https://github.com/prometheus/node_exporter
GitHub - prometheus/node_exporter: Exporter for machine metrics
Exporter for machine metrics. Contribute to prometheus/node_exporter development by creating an account on GitHub.
github.com
โ ๊ณต์ Download
https://prometheus.io/download/#node_exporter
Download | Prometheus
An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
prometheus.io
Redis๋ฅผ ์ค์นํ ์ธ์คํด์ค์ ๋ฉํธ๋ฆญ์ ์์งํ ๊ฒ์ด๋ฏ๋ก Redis ์ค์นํ ์ธ์คํด์ค(monitored)์ Node Exporter๋ฅผ ์ค์นํฉ๋๋ค.
1. ์ค์น ๋ฐ ์คํ
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar xvfz node_exporter-1.5.0.linux-amd64.tar.gz
mv node_exporter-1.5.0.linux-amd64.tar.gz node_exporter
cd node_exporter
nohup ./node_exporter > node_exporter.log 2>&1 &
2. ํ์ธ
Node Exporter์ ์ํด ์์ง๋ ๋ฉํธ๋ฆญ๋ค์ ๋ณผ ์ ์์ต๋๋ค.
curl http://localhost:9100/metrics | grep "node_"
3. ๋ณด์๊ทธ๋ฃน 9100๋ฒ ์ด์ด์ฃผ๊ธฐ
4. ์ ์
Node Exporter์ ์ํด ์์ง๋ ๋ฉํธ๋ฆญ๋ค์ ์น์์ ๋ณผ ์ ์์ต๋๋ค.
http://[IP]:9100/metrics
Redis Exporter
โ ๊ณต์ Github
https://github.com/oliver006/redis_exporter
GitHub - oliver006/redis_exporter: Prometheus Exporter for Redis Metrics. Supports Redis 2.x, 3.x, 4.x, 5.x, 6.x, and 7.x
Prometheus Exporter for Redis Metrics. Supports Redis 2.x, 3.x, 4.x, 5.x, 6.x, and 7.x - GitHub - oliver006/redis_exporter: Prometheus Exporter for Redis Metrics. Supports Redis 2.x, 3.x, 4.x, 5.x,...
github.com
Redis๋ฅผ ์ค์นํ ์ธ์คํด์ค์ Redis Exporter๋ฅผ ์ค์นํฉ๋๋ค.
์ด๋ Redis์ ๋ฉํธ๋ฆญ์ ์์งํ๊ธฐ ์ํจ์ ๋๋ค.
1. Go ์ค์น
redis exporter ์ค์น์ Go ๋น๋ ๊ณผ์ ์ด ์๊ธฐ ๋๋ฌธ์ Go๋ฅผ ์ค์นํด์ค๋๋ค.
wget https://go.dev/dl/go1.20.4.linux-amd64.tar.gz
sudo tar xfz go1.20.4.linux-amd64.tar.gz -C /usr/local
sudo vi /etc/profile
###golang
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
go version
# go version go1.20.4 linux/amd64
2. ๋ณด์๊ทธ๋ฃน 9120, 9121 ์ด์ด์ฃผ๊ธฐ
3. ์ค์น ๋ฐ ์คํ
git clone https://github.com/oliver006/redis_exporter.git
cd redis_exporter
go build .
# redis๊ฐ ๋์์ ธ์์ด์ผ ํจ
nohup ./redis_exporter -redis.addr=redis://localhost:6379 -web.listen-address=:9121 &
nohup ./redis_exporter -redis.addr=redis://localhost:6378 -web.listen-address=:9120 &
Prometheus
์์์ Node Exporter๊ฐ ์คํ์ด์๋ค๋ฉด Prometheus๋ ๊ตญ์ ์๊ณผ ๊ฐ์ต๋๋ค.
Node Exporter ๋ฑ์ด ์๋ฒ์ ์ ๋ณด(๋ฉํธ๋ฆญ)๋ฅผ ๋ชจ์์ฃผ์๋ค๋ฉด Prometheus๋ ์ฃผ๊ธฐ์ ์ผ๋ก pull ์์ฒญ์ ํด ๋ฉํธ๋ฆญ์ ์์งํฉ๋๋ค.
โ ๊ณต์ ๋ฌธ์
https://prometheus.io/docs/prometheus/latest/installation/
Installation | Prometheus
An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
prometheus.io
Redis๋ฅผ ์ค์นํ ์ธ์คํด์ค ๋ง๊ณ ๋ค๋ฅธ ์ธ์คํด์ค(monitoring)์ Prometheus๋ฅผ ์ค์นํฉ๋๋ค.
1. ์ค์น ๋ฐ ์คํ
wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz
tar xvzf prometheus-2.44.0.linux-amd64.tar.gz
mv prometheus-2.44.0.linux-amd64 prometheus
cd prometheus
nohup ./prometheus > prometheus.log /dev/null 2>&1 &
2. ๋ณด์๊ทธ๋ฃน 9090๋ฒ ์ด์ด์ฃผ๊ธฐ
3. ํ์ธ
- ํ๋ก์ธ์ค ํ์ธ
ps -ef | grep prometheus
- Listen ํฌํธ ํ์ธ
netstat -lntup | grep prometheus
4. ์ ์
์๋ ์ฃผ์์ ์ ์ํ๋ฉด ํ๋ก๋ฉํ ์ฐ์ค๊ฐ ์ ๋จ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
http://[IP]:9090/
Prometheus์ Node Exporter, Redis Exporter ์ฐ๊ฒฐ
ํ๋ก๋ฉํ ์ฐ์ค์ Exporter๋ค์ ์ฐ๊ฒฐํด์ฃผ๊ฒ ์ต๋๋ค.
1. prometheus.yml์ ์ด๊ณ targets์ Node Exporter, Redis Exporter ์ฃผ์๋ฅผ ์ ๋ ฅํฉ๋๋ค.
vi prometheus.yml
job_name๊ณผ targets๋ฅผ ์ถ๊ฐํด์ค๋๋ค.
redis๋ฅผ 2๊ฐ์ง ๋ฒ์ ์ผ๋ก ์ค์นํ๊ธฐ ๋๋ฌธ์ ๊ฐ๊ฐ ๊ธฐ์ ํด์ค๋๋ค.
2. Prometheus ๋ชจ๋ํฐ๋ง ํ์ด์ง์์ ์ฐ๊ฒฐ ํ์ธ
- prometheus ์ธ์คํด์ค์์ node_exporter, redis_exporter ์ธ์คํด์ค์ ์ ๊ทผํ ์ ์๊ฒ ๋ณด์๊ทธ๋ฃน ํ์ฉํด์ฃผ์ด์ผ ํจ
3. Prometheus ๋ชจ๋ํฐ๋ง ํ์ด์ง์์ node_exporter ์ฐ๊ฒฐ ํ์ธ
- prometheus ์ธ์คํด์ค์์ node_exporter ์ธ์คํด์ค์ ์ ๊ทผํ ์ ์๊ฒ ๋ณด์๊ทธ๋ฃน ํ์ฉํด์ฃผ์ด์ผ ํจ
- [IP]:9090/graph ์ ์
- go_memstats_gc_sys_bytes ์ ๋ ฅ ํ Execute ๋ฒํผ ํด๋ฆญ
- Graph ํญ ์ ํ
- ์์ง๋๋ ๋ฐ์ดํฐ ํ์ธ
- raw ๋ฐ์ดํฐ ํ์ธ์ด ํ์ํ ๊ฒฝ์ฐ (http://[IP]:9100/metrics) ์ ์
Grafana
Grafana๋ ๋ชจ์ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ์๊ฐํํ๋ ๋๊ตฌ์ ๋๋ค.
โ ๊ณต์ ๋ฌธ์
https://grafana.com/grafana/download/9.5.2
Download Grafana | Grafana Labs
Overview of how to download and install different versions of Grafana on different operating systems.
grafana.com
1. ์ค์น ๋ฐ ์คํ
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.5.2.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-9.5.2.linux-amd64.tar.gz
cd grafana-9.5.2/bin
nohup ./grafana-server > grafana.log 2>&1 &
2. ๋ณด์๊ทธ๋ฃน 3000๋ฒ ์ด์ด์ฃผ๊ธฐ
3. ์ ์
http://[IP]:3000/
4. ID: admin / PW: admin ์ผ๋ก ๋ก๊ทธ์ธ
5. ์ ์
Grafana์ Prometheus ์ฐ๊ฒฐ
Prometheus์ ์์ง๋์ด ์๋ ๋ฉํธ๋ฆญ์ Grafana์์ ํ์ธํ๊ธฐ ์ํด Grafana์ Prometheus ์ ๋ณด๋ฅผ ์ ๋ ฅํด ์ฐ๊ฒฐํด์ค๋๋ค.
1. Administration > Data sources > + Add new data source ํด๋ฆญ
2. Prometheus ์ ํ
3. URL์ IP:9090๋ฅผ ์
๋ ฅํ๊ณ , ํ๋จ์ Save & Test ํด๋ฆญ
Grafana์ ๋์๋ณด๋ ์ฐ๊ฒฐํ๊ธฐ
ํ์ฌ ์ฐ๊ฒฐํ Prometheus์๋ ์ด 3๊ฐ์ exporter๊ฐ ๋ฑ๋ก๋์ด ์์ต๋๋ค.
Node Exporter๋ node exporter ๋์๋ณด๋ ํ ํ๋ฆฟ์ ์ฐ๊ฒฐ,
Redis Exporter๋ redis exporter ๋์๋ณด๋ ํ ํ๋ฆฟ์ ์ฐ๊ฒฐํด๋ณด๊ฒ ์ต๋๋ค.
์ถ๊ฐ๋ก Redis ์์ฒด๋ Redis Plugin์ ์ค์นํด์ ์ฐ๊ฒฐํด๋ณผ ๊ฒ์ ๋๋ค.
1) ๋์๋ณด๋ ํ ํ๋ฆฟ ๋ค์ด๋ก๋
๋จผ์ ์ ๋ง๋ค์ด์ง ๋์๋ณด๋ ํ ํ๋ฆฟ์ ๋ค์ด๋ก๋ ๋ฐ์ต๋๋ค.
Node Exporter ๋์๋ณด๋ ํ ํ๋ฆฟ์ ๋๋ค. ๋ค์ด๊ฐ์ Download JSON์ผ๋ก ํ์ผ์ ๋ค์ด๋ฐ์ต๋๋ค.
2) Grafana์ import
- http://[IP]:3000/dashboard/import
ํด๋น ํ์ด์ง์์ ๋ค์ด๋ก๋ ๋ฐ์ node exporter์ redis exporter์ฉ ๋์๋ณด๋ JSON ํ์ผ์ ์ ๋ก๋ํ๊ณ ํ๋จ์ Load ๋ฒํผ์ ๋๋ฆ ๋๋ค.
3) ํ์ผ๋ณ๋ก Prometheus์ exporter ์ฐ๊ฒฐ
4) Redis ํ๋ฌ๊ทธ์ธ ์ค์น
5) Redis ์ฐ๊ฒฐ
6.2.9์ 7.0.11์ ๊ฐ๊ฐ ์ฐ๊ฒฐํด์ค๋๋ค.
์ด ๋ Redis์ ์ธ๋ถ ํต์ ์ด ํ์ฉ๋์ด ์์ด์ผ ํฉ๋๋ค. (redis.conf : bind, protected-mode ์์ฑ)
6) ๊ฒฐ๊ณผ
- Data sources ์ฐ๊ฒฐ ๋ชฉ๋ก
- Dashboards ์ฐ๊ฒฐ ๋ชฉ๋ก
- Node Exporter ๋์๋ณด๋
- Redis Exporter ๋์๋ณด๋
- Redis ๋์๋ณด๋
Dooray! ์ธ์ปค๋ฐ ํ ์๋ฆผ ์ค์
โ
๊ณต์ Github
https://github.com/prometheus/alertmanager
1. Alertmanager ์ค์น
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz
tar xvzf alertmanager-0.25.0.linux-amd64.tar.gz
mv alertmanager-0.25.0.linux-amd64.tar.gz alertmanager
cd alertmanager/
nohup ./alertmanager > alertmanager.log 2>&1 &
2. Prometheus Alert rules ์ค์
- Node Exporter Rules ์์ฑ
- Redis Exporter Rules ์์ฑ
- prometheus.yml์ ๋ฑ๋ก
- Grafana์ ์ฐ๋ ํ์ธ
3. Dooray! web hook ์ฐ๋
alertmanager.yml์ ์ฑํ
๋ฐฉ ์น ํ
์ ์ถ๊ฐํฉ๋๋ค.
4. ๊ฒฐ๊ณผ
- alertmanager
- Dooray! ๋ฉ์์ง ์๋ฆผ
- ๋ฌธ์ ๋ฐ์
- Alertmanager์์ ๊ธฐ์กด์๋ ๋ฉ์์ง ์ปค์คํฐ๋ง์ด์ง์ด ๊ฐ๋ฅํ์ง๋ง ํ์ฌ๋ ์ปค์คํ ์ ํ ๊ฒฝ์ฐ, ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
- ์๋ํด๋ณธ ๋ฐฉ๋ฒ
- Alertmanager์์ ๋ฐ์ํ๋ ์๋ฆผ์ Grafana๋ก ๋ฐ๊ธฐ
- Grafana์ alert rules๋ฅผ ๋ฐ๋ก ๋ฑ๋กํด์ ์๋ฆผ ๋ฐ๊ธฐ
์ฐธ๊ณ ์ฌ์ดํธ
- https://velog.io/@dev_leewoooo/Redis์-metrics๋ฅผ-๋ชจ๋ํฐ๋งํด๋ณด์
- https://nauco.tistory.com/45
- https://velog.io/@sojukang/์ธ์์์-์ ์ผ-์ฌ์ด-Prometheus-Grafana-๋ชจ๋ํฐ๋ง-์ค์
- https://mycup.tistory.com/320
- https://sangchul.kr/entry/%EB%A6%AC%EB%88%85%EC%8A%A4-centos7%EC%97%90-gogolang-%EC%84%A4%EC%B9%98
- https://sh-safer.tistory.com/204
- https://pinggoopark.tistory.com/795