blackbox_exporter安装
作者:互联网
本文主要介绍如何使用blackbox_exporter的收集被监控主机的网站状态、端口等信息,借助 Prometheus 最终以仪表盘的形式显示在 Grafana 中。
blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。
2.blackbox_exporter 应用场景
HTTP 测试
定义 Request Header 信息
判断 Http status / Http Respones Header / Http Body 内容
TCP 测试
业务组件端口状态监听
应用层协议定义与监听
ICMP 测试
主机探活机制
POST 测试
接口联通性
SSL 证书过期时间
3. 安装blackbox_exporter
3.1 各个版本的blackbox_exporter如下:
$ wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.15.1/blackbox_exporter-0.15.1.linux-amd64.tar.gz
$ tar -xvf blackbox_exporter-0.15.1.linux-amd64.tar.gz
$ mv blackbox_exporter-0.15.1.linux-amd64 /home/blackbox_exporter
3.3 创建systemd服务
vim /lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
ExecStart=/home/blackbox_exporter/blackbox_exporter --config.file=/home/blackbox_exporter/blackbox.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start blackbox_exporter
3.5 验证是否启动成功 默认监听端口为9115
$ systemctl status blackbox_exporter
$ netstat -lnpt|grep 9115
prometheus.yml中加入blackbox_exporter
[root@prometheus prometheus]# cat 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:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
- "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: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["192.168.61.170:20015","192.168.61.171:20015"]
#监控tcp端口
- job_name: "port_status"
metrics_path: /probe
params:
module: [tcp_connect]
file_sd_configs:
- files:
- "/home/prometheus/file_sd/services.yml"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.61.169:9115
[root@prometheus prometheus]# cat file_sd/services.yml
- targets:
- 192.168.61.170:20015
- 192.168.61.171:22
- 172.20.3.85:9600
labels:
# group: catcher
tag: ssh
- targets:
- 192.168.61.170:22
labels:
# group: datahub
[root@prometheus prometheus]# cat rules/blackbox_network_stats.yml
groups:
- name: blackbox_network_stats
rules:
- alert: '服务探测失败'
expr: probe_success == 0
for: 60s
labels:
severity: high
alertinfo: push_blackbox_alert
annotations:
summary: "{{ $labels.instance }}探测失败"
description: "服务探测失败,请检查业务是否正常!!!"
标签:__,exporter,blackbox,target,prometheus,安装,yml 来源: https://www.cnblogs.com/xgsh/p/16645012.html