prometheus blackbox_exporter

Posted 梦想不遥远

tags:

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

一、概述

1、 HTTP 测试

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

2、 TCP 测试

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

3、 ICMP 测试

  • 主机探活机制

4、 POST 测试

  • 接口联通性

5、 SSL 证书过期时间

二、安装

blackbox_exporter安装包

以linux系统为例,下载编译好的二进制包,解压使用:

1、下载并解压

# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz
# tar -zxvf blackbox_exporter-0.19.0.linux-amd64.tar.gz 
# cd blackbox_exporter-0.19.0.linux-amd64/

2、验证是否安装成功

# ./blackbox_exporter --version
blackbox_exporter, version 0.19.0 (branch: HEAD, revision: 5d575b88eb12c65720862e8ad2c5890ba33d1ed0)
  build user:       root@2b0258d5a55a
  build date:       20210510-12:56:44
  go version:       go1.16.4
  platform:         linux/amd64

3、启动blackbox_exporter

nohup ./blackbox_exporter &

4、验证是否启动成功

# netstat -utpln|grep blackbox
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::9115                 :::*                    LISTEN      25185/./blackbox_ex 

5、创建systemcd服务(centos7系统可以用)

$ 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

三、prometheus.yml中加入blackbox_exporter

1、监控主机存活状态

# vim prometheus.yml
- job_name: crawler_status
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets: [\'10.45.3.8\',\'10.45.3.9\',\'10.45.3.10\',\'10.45.3.11\']
        labels:
          instance: node_status
          group: \'node\'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115

2、监控主机端口存活状态

- job_name: \'crawler_port_status\'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets: [\'10.45.3.8:3128\']
        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: 127.0.0.1:9115

3、监控网站状态

- job_name: qianxin_web_status
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets: [\'https://www.qianxin.com\']
        labels:
          instance: qianxin_web_status
          group: \'web\'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 127.0.0.1:9115

- job_name: baidu_web_status
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets: [\'https://www.baidu.com\']
        labels:
          instance: baidu_web_status
          group: \'web\'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 127.0.0.1:9115

- job_name: jd_web_status
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets: [\'https://www.jd.com\']
        labels:
          instance: jd_web_status
          group: \'web\'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 127.0.0.1:9115

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

# ./promtool check config prometheus.yml

5、重启prometheus

6、查看targets界面

四、grafana中加入blackbox_exporter监控数据

1、安装grafana

# docker run -d -p 3000:3000 --name grafana grafana/grafana

2、添加数据源



五、grafana中加入blackbox_exporter监控数据

1、添加模版

https://grafana.com/grafana/dashboards/9965
https://grafana.com/grafana/dashboards/9719

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

# docker exec -it grafana grafana-cli plugins install grafana-piechart-panel
# docker restart grafana

以上是关于prometheus blackbox_exporter的主要内容,如果未能解决你的问题,请参考以下文章

prometheus视频教程

grafana和prometheus系列六:prometheus默认存储

2019最新 prometheus视频教程 prometheus监控视频 prometheus入门与实践教程

2019最新 prometheus视频教程 prometheus监控视频 prometheus入门与实践教程

Prometheus简介

Prometheus学习系列之Prometheus 联盟迁移