Table of Contents
(Deprecated) Install Prometheus with docker
선행작업
- 도커 설치
prometheus 설치
sudo mkdir -p /data/docker/prometheus/
sudo vi /data/docker/prometheus/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: ['172.31.16.237:9090']
docker run \
-p 9090:9090 \
-v /data/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
브라우저에서 정상 작동을 확인할 수 있습니다.
http://XXX.XXX.XXX.XXX:9090/
Status > Targets
에서 prometheus
가 정상적으로 작동하는 것을 확인할 수 있습니다.
node_exporter 설치
node_exporter
는 host
를 모니터링하는 것이 기능이라, docker
로 설치하는 것은 비추라고 합니다.
그래서, 그냥 바이너리를 다운받아 설치합니다.
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz
sudo mv node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin/
서비스로 등록합니다.
sudo vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
sudo useradd -M -r -s /bin/false node_exporter
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl status node_exporter
sudo systemctl enable node_exporter
prometheus 와 node_exporter 연동
sudo vi /data/docker/prometheus/prometheus.yml
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['172.31.16.237:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['172.31.16.237:9100']
docker run \
-p 9090:9090 \
-v /data/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
docker-compose
를 이용해 실행합니다.
vi docker-compose.yml
version: '3.7'
services:
prometheus:
image: prom/prometheus
container_name: prometheus
volumes:
- /data/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- 9090:9090
restart: always
volumes:
prometheus_data: {}
docker-compose up -d
alertmanager 설치
sudo mkdir -p /data/docker/alertmanager/
sudo vi /data/docker/alertmanager/alertmanager.yml
global:
smtp_smarthost: localhost:25
smtp_from: alertmanager@example.com
route:
group_wait: 10s
group_interval: 10s
repeat_interval: 10s
receiver: alertmanager_test
receivers:
- name: 'alertmanager_test'
email_configs:
- to: 'team-X+alerts@example.org, team-Y+alerts@example.org'
sudo vi /data/docker/alertmanager/alert.rules
groups:
- name: slackal
rules:
- alert: SlackAlert
expr: db_status == 0
# for: 1s
annotations:
text: "DB server is down"
vi docker-compose.yml
version: '3.7'
services:
alertmanager:
image: prom/alertmanager
container_name: alertmanager
volumes:
- /data/docker/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
ports:
- 9093:9093
restart: always
prometheus:
image: prom/prometheus
container_name: prometheus
volumes:
- /data/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- /data/docker/alertmanager/alert.rules:/etc/alertmanager/alert.rules
- prometheus_data:/prometheus
ports:
- 9090:9090
restart: always
volumes:
prometheus_data: {}
sudo vi /data/docker/prometheus/prometheus.yml
rule_files:
- /etc/alertmanager/alert.rules
alerting:
alertmanagers:
- static_configs:
- targets: ['172.31.11.235:9093']
docker-compose stop
docker-compose up -d
Grafana 설치
sudo mkdir -p /data/docker/grafana/data
vi docker-compose.yml
# ......
grafana:
image: grafana/grafana
container_name: grafana
depends_on:
- prometheus
ports:
- 3000:3000
volumes:
- /data/docker/grafana/data:/var/lib/grafana
restart: always
# docker-compose down
docker-compose stop
docker-compose up -d
브라우저에서 정상 작동을 확인할 수 있습니다.
http://XXX.XXX.XXX.XXX:3000/
디폴트 로그인정보는 admin/admin
입니다.
dashboard import
grafana url 을 입력해서 dashboard 를 import 할 수 있습니다.
1
Pingback: Prometheus Elasticsearch 모니터링하기 – 상구리의 기술 블로그