prometheus的插件blackbox_exporter实现黑盒监控http,https,tcp,dns以及ICMP协议进行探测
环境:centos7、prometheus2.24、grafana
1、下载插件blackbox_exporter https://github.com/prometheus/blackbox_exporter/releases
1 | wget https: //github .com /prometheus/blackbox_exporter/releases/download/v0 .18.0 /blackbox_exporter-0 .18.0.linux-amd64. tar .gz |
2、安装blackbox_exporter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #解压 tar -zxvf blackbox_exporter-0.18.0.linux-amd64. tar .gz #移动文件 mv blackbox_exporter-0.18.0.linux-amd64/ /usr/local/blackbox_exporter #创建system服务 vim /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 && systemctl enable blackbox_exporter |
3、验证服务
1 2 3 | 默认监听端口为9115 systemctl status blackbox_exporter ss -lnt| grep 9115 |
4、prometheus.yml中加入blackbox_exporter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 监控主机存活状态 $ vim /usr/local/prometheus/prometheus .yml - job_name: 'node_status' metrics_path: /probe params: module: [icmp] static_configs: - targets: [ '127.0.0.1' ] labels: instance: 'node_status' group: 'node' relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 127.0.0.1:9115 监控主机端口存活状态 $ vim /usr/local/prometheus/prometheus .yml - job_name: 'port_status' metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: [ '127.0.0.1:9100' , '127.0.0.1:9090' ] labels: instance: 'port_status' group: 'tcp' relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 127.0.0.1:9115 监控网站状态 $ vim /usr/local/prometheus/prometheus .yml - job_name: web_status metrics_path: /probe params: module: [http_2xx] static_configs: - targets: [ 'https://www.baidu.com' ] labels: instance: web_status group: web relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 127.0.0.1:9115 检查配置文件是否书写正确 $ cd /usr/local/prometheus $ . /promtool check config prometheus.yml 重新加载prometheus的配置 $ systemctl reload prometheus |
5、grafana官网下载web的dashboard模板导入查看结果
模板下载:https://grafana.com/grafana/dashboards/9965
模板中的饼状图插件下载:https://grafana.com/grafana/plugins/grafana-piechart-panel
做一个决定,并不难,难的是付诸行动,并且坚持到底。
分类:
监控
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)