Prometheus监控之Blackbox_exporter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus监控之Blackbox_exporter相关的知识,希望对你有一定的参考价值。

一、简介

Blackbox_exporter是Prometheus官方提供的一个exporter,可以监控HTTP,HTTPS,DNS,TCP,ICMP和gRPC等目标实例,从而实现对被监控节点进行监控和数据采集。

下载地址:
https://github.com/prometheus/blackbox_exporter

tar -xvf blackbox_exporter-0.22.0.linux-amd64.tar.gz
mv blackbox_exporter-0.22.0.linux-amd64 blackbox_exporter
/usr/local/blackbox_exporter/blackbox_exporter \\
--config.file="/usr/local/blackbox_exporter/blackbox.yml" \\
--web.listen-address="10.10.10.10:9115" &>blackbox_exporter.log &

启动参数有
--web.config.file="" #就可以配置TLS
--web.listen-address="10.10.10.10:9115" #指定ip和端口

设置开机自启
vi /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=Prometheus blackbox exporter
After=network.target

[Service]
Type=simple
User=root
Group=root
Restart=on-failure
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \\
--config.file="/usr/local/blackbox_exporter/blackbox.yml" \\
--web.listen-address="10.10.10.10:9115"

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl restart blackbox_exporter.service

二、搭建

blackbox_exporter的监控,包括URL,ICMP,TCP等。都是先在prometheus设置监控内容,再转发到blackbox_exporter的地址,最后得出监控结果。

1、URL监控

在prometheus服务器添加url监控工作,末尾指定blackbox_exporter地址:
scrape_configs:
- job_name: blackbox
metrics_path: /probe
params:
module: [http_2xx] # Look for a HTTP 200 response.
static_configs:
- targets:
- http://baidu.com # Target to probe with http.
- https://baidu.com # Target to probe with https.
- http://example.com:8080 # Target to probe with http on port 8080.
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.10.10.10:9115 # The blackbox exporters real hostname:port.

在blackbox_exporter服务器查看最近URL探测:

2、ICPM监控

ICMP就是Ping使用的协议,可以探测IP是否在线:
scrape_configs:
- job_name: ping_status
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets:
- 192.168.10.131
- 192.168.10.132
- 192.168.10.133
labels:
instance: ping_status
group: icmp
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: ip
- target_label: __address__
replacement: 10.10.10.10:9115

在blackbox_exporter服务器查看最近ICMP探测:

3、PORT监控

Port端口用于检测服务器端口是否开启,服务是否可用:
scrape_configs:
- job_name: port_status
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: [192.168.10.131:22,192.168.10.132:3306,192.168.10.133:8080]
labels:
instance: port_status
group: port
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: ip
- target_label: __address__
replacement: 10.10.10.10:9115

在blackbox_exporter服务器查看最近Port探测:

以上是关于Prometheus监控之Blackbox_exporter的主要内容,如果未能解决你的问题,请参考以下文章

prometheus监控之Mysql监控

Prometheus监控之简介

监控平台设计 之 Prometheus 存储 LevelDB

性能监控之初识 Prometheus

Linux-监控三剑客之prometheus

Prometheus监控之Federation机制配置