prometheus的插件blackbox_exporter实现黑盒监控http,https,tcp,dns以及ICMP协议进行探测
环境:centos7、prometheus2.24、grafana
1、下载插件blackbox_exporter https://github.com/prometheus/blackbox_exporter/releases
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.18.0/blackbox_exporter-0.18.0.linux-amd64.tar.gz
2、安装blackbox_exporter
#解压 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、验证服务
默认监听端口为9115 systemctl status blackbox_exporter ss -lnt|grep 9115
4、prometheus.yml中加入blackbox_exporter
监控主机存活状态 $ 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
做一个决定,并不难,难的是付诸行动,并且坚持到底。