前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Blackbox_exporter黑盒监测

Blackbox_exporter黑盒监测

作者头像
py3study
发布2020-03-18 11:07:02
2.3K0
发布2020-03-18 11:07:02
举报
文章被收录于专栏:python3

一、概述

blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。 Blackbox_exporter 应用场景

  • HTTP 测试

          定义 Request Header 信息           判断 Http status / Http Respones Header / Http Body 内容

  • TCP 测试

          业务组件端口状态监听            应用层协议定义与监听

  • ICMP 测试

           主机探活机制

  • POST 测试

          接口联通性

  • SSL 证书过期时间

二、安装

环境说明

操作系统:centos 6.9

下载解压

各个版本的blackbox_exporter https://github.com/prometheus/blackbox_exporter/releases 以linux系统为例,下载编译好的二进制包,解压使用:

代码语言:javascript
复制
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
tar -zxvf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /data
mv /data/blackbox_exporter-0.16.0.linux-amd64 /data/blackbox_exporter

验证是否安装成功

代码语言:javascript
复制
# cd /data/blackbox_exporter/
# ./blackbox_exporter --version
blackbox_exporter, version 0.16.0 (branch: HEAD, revision: 991f89846ae10db22a3933356a7d196642fcb9a9)
  build user:       root@64f600555645
  build date:       20191111-16:27:24
  go version:       go1.13.4

启动blackbox_exporter

代码语言:javascript
复制
nohup ./blackbox_exporter &

验证是否启动成功

默认监听端口为9115

代码语言:javascript
复制
# ss -tunlp|grep 9115
tcp    LISTEN     0      32768                  *:9115                  *:*      users:(("blackbox_export",29880,3))

三、prometheus.yml中加入blackbox_exporter

监控主机存活状态

编辑prometheus配置文件

代码语言:javascript
复制
vi /data/prometheus/prometheus.yml

最后一行添加

代码语言:javascript
复制
- job_name: node_status
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets: ['10.165.94.31']
        labels:
          instance: node_status
          group: 'node'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 172.19.155.133:9115

注意:10.165.94.31是被监控端ip,172.19.155.133是Blackbox_exporter

监控主机端口存活状态

代码语言:javascript
复制
- job_name: 'prometheus_port_status'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets: ['172.19.155.133:8765']
        labels:
          instance: 'port_status'
          group: 'tcp'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.19.155.133:9115

监控网站状态

代码语言:javascript
复制
- job_name: web_status
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets: ['http://www.baidu.com']
        labels:
          instance: user_status
          group: 'web'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 172.19.155.133:9115

检查配置文件是否书写正确

代码语言:javascript
复制
cd /data/prometheus
./promtool check config prometheus.yml

重启prometheus

代码语言:javascript
复制
service restart prometheus

访问targets界面

访问 http://127.0.0.1:9090/targets 查看加入的监控信息。

1.png
1.png

确保状态为 UP

四、grafana中加入blackbox_exporter监控数据

导入blackbox_exporter模板

此模板为9965号模板,数据源选择Prometheus 模板下载地址 https://grafana.com/grafana/dashboards/9965

1.png
1.png

此模板需要安装饼状图插件 下载地址 https://grafana.com/grafana/plugins/grafana-piechart-panel 安装插件,重启grafana生效。

代码语言:javascript
复制
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart

访问grafana

访问 http://127.0.0.1:3000,查看数据。

1.png
1.png

本文参考链接:

https://blog.csdn.net/qq_43190337/article/details/100577728

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/03/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、概述
  • 二、安装
    • 环境说明
      • 下载解压
        • 验证是否安装成功
          • 启动blackbox_exporter
            • 验证是否启动成功
            • 三、prometheus.yml中加入blackbox_exporter
              • 监控主机存活状态
                • 监控主机端口存活状态
                  • 监控网站状态
                    • 访问targets界面
                    • 四、grafana中加入blackbox_exporter监控数据
                      • 导入blackbox_exporter模板
                        • 访问grafana
                        相关产品与服务
                        Grafana 服务
                        Grafana 服务(TencentCloud Managed Service for Grafana,TCMG)是腾讯云基于社区广受欢迎的开源可视化项目 Grafana ,并与 Grafana Lab 合作开发的托管服务。TCMG 为您提供安全、免运维 Grafana 的能力,内建腾讯云多种数据源插件,如 Prometheus 监控服务、容器服务、日志服务 、Graphite 和 InfluxDB 等,最终实现数据的统一可视化。
                        领券
                        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档