一、blackbox_exporter應用場景
HTTP 測試: 定義 Request Header 信息、判斷 Http status / Http Respones Header / Http Body 內容
TCP 測試: 業務組件端口狀態監聽、應用層協議定義與監聽
ICMP 測試: 主機探活機制
POST 測試: 接口聯通性
SSL證書過期時間
二、blackbox_exporter安裝
# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz # tar xf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/ # ln -s /usr/local/blackbox_exporter-0.16.0.linux-amd64/ /usr/local/blackbox_exporter # 使用systemd進行管理blackbox_exporter服務 # vim /usr/lib/systemd/system/blackbox_exporter.service [Unit] Description=blackbox_exporter After=network.target [Service] User=root Type=simple ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml Restart=on-failure [Install] WantedBy=multi-user.target # systemctl daemon-reload # systemctl start blackbox_exporter.service # systemctl enable blackbox_exporter.service
三、配置prometheus采集數據
# cd /usr/local/prometheus
# vim prometheus.yml
# my global config
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.5.237:9090']
- job_name: 'node'
file_sd_configs:
- refresh_interval: 30s
files:
- "/usr/local/prometheus/sd_config/node*.yml"
- job_name: 'docker'
static_configs:
- targets: ['192.168.5.85:8080']
- job_name: 'mysql'
static_configs:
- targets: ['192.168.5.237:9104']
labels:
app: zabbix-server-mysql
# 網站監控
- job_name: 'http_status'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://www.lzfn.com', 'wiki.lzfn.com']
labels:
instance: http_status
group: web
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.5.85:9115
# ping 檢測
- job_name: 'ping_status'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['192.168.5.85']
labels:
instance: 'ping_status'
group: 'icmp'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.5.85:9115
# 端口監控
- job_name: 'port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.5.85:80', '192.168.5.85:9000', '192.168.5.85:8080']
labels:
instance: 'port_status'
group: 'port'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.5.85:9115
# 檢查配置文件並重啟服務
# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 0 rule files found
# systemctl restart prometheus.service
四、配置Grafana展示數據
使用9965模板,需要安裝餅狀態圖插件,安裝后重啟grafana
grafana-cli plugins install grafana-piechart-panel systemctl restart grafana-server.service



