Prometheus基于blackbox_exporter监控
blackbox_exporter 监控组件
blackbox_exporter 是 Prometheus 官方提供的一个 exporter,可以监控 HTTP、 HTTPS,、DNS、 TCP 、ICMP 等目标实例,从而实现对被监控节点进行监控 和数据采集。promethes调用blackbox_exporter去访问目标监控服务器,实现指标的采集
prometheus blackbox_exporter下载地址:Download | Prometheus
HTTP/HTPPS:URL/API 可用性检测
TCP:端口监听检测
ICMP:主机存活检测
DNS:域名解析
下载和部署blackbox_exporter
https://github.com/prometheus/blackbox_exporter
root@prometheus:~# tar xf blackbox_exporter-0.22.0.linux-amd64.tar.gz -C /usr/local/ root@prometheus:~# cd /usr/local/ root@prometheus:/usr/local# ln -s blackbox_exporter-0.22.0.linux-amd64 blackbox_exporter
blackbox的配置文件中只是制定了监控的类型模块,真正监控具体的数据实在prometheus-server上配置
root@prometheus:/usr/local/blackbox_exporter# cat blackbox.yml modules: http_2xx: prober: http http_post_2xx: prober: http http: method: POST tcp_connect: prober: tcp pop3s_banner: prober: tcp tcp: query_response: - expect: "^+OK" tls: true tls_config: insecure_skip_verify: false grpc: prober: grpc grpc: tls: true preferred_ip_protocol: "ip4" grpc_plain: prober: grpc grpc: tls: false service: "service1" ssh_banner: prober: tcp tcp: query_response: - expect: "^SSH-2.0-" - send: "SSH-2.0-blackbox-ssh-check" irc_banner: prober: tcp tcp: query_response: - send: "NICK prober" - send: "USER prober prober prober :prober" - expect: "PING :([^ ]+)" send: "PONG ${1}" - expect: "^:[^ ]+ 001" icmp: prober: icmp icmp_ttl5: prober: icmp timeout: 5s icmp: ttl: 5
创建blackbox_exporter service启动文件,默认监听9115端口
vim /etc/systemd/system/blackbox-exporter.service [Unit] Description=Prometheus Blackbox Exporter After=network.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \ --config.file=/usr/local/blackbox_exporter/blackbox.yml \ --web.listen-address=:9115 Restart=on-failure [Install] WantedBy=multi-user.target
启动blackbox_exporter
systemctl daemon-reload && systemctl enable blackbox-exporter.service && systemctl start blackbox-exporter.service
验证web界面 IP:9115
访问URI: /metrics
blackbox exporter 实现 URL 监控
prometheus-server 调用 blackbox exporter 实现对 URL/ICMP 的监控。blackbox的配置文件中只是制定了监控的类型模块,真正监控具体的数据实在prometheus-server上配置
Prometheus URL 监控配置:
- job_name: 'http_status' metrics_path: /probe params: module: [http_2xx] static_configs: - targets: ['http://www.test.com'] #可以指定多个target,以逗号分隔 labels: instance: http_status group: web relabel_configs: - source_labels: [__address__] #将__address__(当前监控目标URL地址的标签)修改为__param_target,用于传递给blackbox_exporter target_label: __param_target #标签key为__param_target、value为 www.test.com。 - source_labels: [__param_target] #基于__param_target 获取监控目标 target_label: url - target_label: __address__ #新添加一个目标__address__,指向blackbox_exporter 服务器地址,用于将监控请求发送给指定的 blackbox_exporter 服务器 replacement: 192.168.100.21:9115 #指定 blackbox_exporter 服务器地址
prometheus-server 访问验证
访问blackbox_exporter验证
blackbox exporter 实现 ICMP 监控
Prometheus icmp 监控配置:
- job_name: 'ping_status' metrics_path: /probe params: module: [icmp] static_configs: - targets: ['192.168.100.3',"192.168.100.4"] 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: 192.168.100.21:9115
访问blackbox_exporter验证
访问prometheus-server验证
blackbox exporter 实现端口监控:
prometheus端口监控配置
- job_name: 'port_status' metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: ['192.168.100.4:9100', '192.168.100.7:9090','192.168.100.3:22'] #监控对端服务器的端口 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: 192.168.100.21:9115 #blackbox_exporter地址
blackbox_exporter访问验证
prometheus-server服务验证
grafana导入模板
模板:ID-13587、ID-9965
本文来自博客园,作者:PunchLinux,转载请注明原文链接:https://www.cnblogs.com/punchlinux/p/17035311.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?