Qua bài trên cơ bản ta có thể hiểu Prometheus thu thập data từ các nguồn services sau đó xử lý / phân tích v..v. Đồng nghĩa, installed Prometheus xong ở trên thì ta … chả có gì ! Vì đã có nguồn data đâu. Do đó cần install các services để export data từ các services.
Có rất nhiều exporter tương ứng với các services. Ta chỉ nói trong phạm vi 1 vài exporters cơ bản
- MySQL Exporter
- MongoDB Exporter
- Redis Exporter
- Node Exporter
- Apache Exporter
- Nginx Exporter
- HAProxy Exporter
Sau khi đã installed các exporters ( và make sure it’s running fine 😀 ) thì ta update vào Prometheus /etc/prometheus/prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['192.168.1.10:9093']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "/etc/prometheus/rules/*.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'workstation'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.1.10:9100'] # node exporter
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9093'] # alert manager
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9104'] # mysql
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9216'] # mongodb
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9121'] # redis
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9150'] # memcached
labels:
instance: 'workstation'
- targets: ['192.168.1.10:1936'] # haproxy
labels:
instance: 'workstation'
- targets: ['192.168.1.10:9256'] # process
labels:
instance: 'workstation'
- job_name: 'x300'
static_configs:
- targets: ['192.168.1.11:9100'] # node exporter
labels:
instance: 'x300'
- targets: ['192.168.1.11:9117'] # apache
labels:
instance: 'x300'
- targets: ['192.168.1.11:9104'] # mysql
labels:
instance: 'x300'
- targets: ['192.168.1.11:9121'] # redis
labels:
instance: 'x300'
Và sau đó reload lại config
curl -s -XPOST localhost:9090/-/reload
Sau khi đã config xong ta sẽ có. Nếu exporter nào down thì xem lại config của nó. 1 số lý do có thể cân nhắc
- Firewall của target
Tuy nhiên dù exporter up vẫn có thể báo service mà nó export bị down vì … không connect được. Ví dụ MySQL Exporter không connect được tới MySQL Server.

Về cơ bản đến đây là xong. Đã có thể sử dụng Grafana để render lên. Tuy nhiên còn 1 feature quan trọng của Prometheus – AlertManager
Cũng install như bình thường: Move binary, tạo SystemD, Enable / Start
Sau đó là config các rules cho alert. Có thể tham khảo ở đây. Sau khi mọi thứ được setup hoàn tất ta sẽ có như sau

Từ đây có config để alert tới các Channel mong muốn như Slack / Telegram. Sẽ có 1 bài chi tiết việc này. Vì mình cũng chỉ mới sử dụng cơ bản.
Leave a Reply