구성 방법
Node_exporter 설치 및 설정
# node_exporter 다운로드 및 설치
$ wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
$ sudo tar -xvzf node_exporter-1.0.1.linux-amd64.tar.gz
$ sudo mv node_exporter-1.0.1.linux-amd64.tar.gz/node_exporter /usr/sbin/
# node_exporter 스크립트 등록
$ sudo vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
[Service]
User=ec2-user
EnvironmentFile=/etc/sysconfig/node_exporter
ExecStart=/usr/sbin/node_exporter $OPTIONS
[Install]
WantedBy=multi-user.target
# config 파일 생성
$ sudo mkdir -p /etc/sysconfig
$ sudo touch /etc/sysconfig/node_exporter # OPTIONS="--collector.textfile.directory /var/lib/node_exporter/textfile_collector"
# daemon-reload 및 서비스 시작
$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
$ sudo systemctl start node_exporter.service
# Check
$ curl http://localhost:9100/metrics
Postgresql_exporter 설치 및 설정
# postgres_exporter 설치
$ wget https://github.com/wrouesnel/postgres_exporter/releases/download/v0.8.0/postgres_exporter_v0.8.0_linux-amd64.tar.gz
$ sudo tar -xvzf postgres_exporter_v0.8.0_linux-amd64.tar.gz
$ mv postgres_exporter_v0.8.0_linux-amd64.tar.gz/postgres_exporter /usr/local/bin/
$ sudo chown -R postgres:postgres /usr/local/bin/postgres_exporter
# postgres_exporter 스크립트 등록
$ sudo vi /etc/systemd/system/postgres_exporter.service
[Unit]
Description=Prometheus PostgreSQL Exporter
After=network.target
[Service]
Type=simple
Restart=always
User=postgres
Group=postgres
#Environment=DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable"
Environment=DATA_SOURCE_NAME=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
ExecStart=/usr/local/bin/postgres_exporter
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable postgres_exporter.service
$ sudo systemctl start postgres_exporter.service
# AWS Console Management 접속 및 방화벽 Inbound 9187 허용 추가
# postgres_exporter defendency Package 설치
$ sudo yum -y install git go
$ go get github.com/lib/pq
# configure 설정
$ sudo su postgres
$ cd /data/postgres/data
$ vi pg_hba.conf
----맨 하단부 내용 수정---- (아래 내용이 기존 내용과 수정해서 추가가 되어야함)
local all all md5
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
Prometheus 설정
$ cd prometheus
$ vi prometheus.yml
----맨 하단부 추가----
- job_name: postgresql
static_configs:
- targets: ['서버IP:9187']
labels:
instance: postgres-master
- targets: ['서버IP:9187']
labels:
instance: postgres-slave
$ cd && docker-compose down
$ docker-compose up -d
PostgreSQL_Exporter 재부팅
$ sudo systemctl restart postgres_exporter
$ watch -n 1 systemctl status postgres_exporter
Every 1.0s: systemctl status postgres_exporter
● postgres_exporter.service - Prometheus PostgreSQL Exporter
Loaded: loaded (/etc/systemd/system/postgres_exporter.service; enabled; vendor preset: disabled)
Active: active (running) since 수 2020-12-30 14:02:52 KST; 11min ago
Main PID: 3589 (postgres_export)
CGroup: /system.slice/postgres_exporter.service
└─3589 /usr/local/bin/postgres_exporter