Blackbox_exporter黑盒監測

一、概述

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系統爲例,下載編譯好的二進制包,解壓使用:

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

 

驗證是否安裝成功

# 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

nohup ./blackbox_exporter &

 

驗證是否啓動成功

默認監聽端口爲9115

# ss -tunlp|grep 9115
tcp    LISTEN     0      32768                  *:9115                  *:*      users:(("blackbox_export",29880,3))

 

三、prometheus.yml中加入blackbox_exporter

監控主機存活狀態

編輯prometheus配置文件

vi /data/prometheus/prometheus.yml

最後一行添加

  - 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

 

監控主機端口存活狀態

  - 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

 

監控網站狀態

  - 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

 

檢查配置文件是否書寫正確

cd /data/prometheus
./promtool check config prometheus.yml

 

重啓prometheus

service restart prometheus

 

訪問targets界面

訪問 http://127.0.0.1:9090/targets 查看加入的監控信息。

 

 

 

確保狀態爲 UP 

 

四、grafana中加入blackbox_exporter監控數據

導入blackbox_exporter模板

此模板爲9965號模板,數據源選擇Prometheus 模板下載地址 https://grafana.com/grafana/dashboards/9965

 

 

此模板需要安裝餅狀圖插件 下載地址 https://grafana.com/grafana/plugins/grafana-piechart-panel
安裝插件,重啓grafana生效。

grafana-cli plugins install grafana-piechart-panel
service grafana-server restart

 

訪問grafana

訪問 http://127.0.0.1:3000,查看數據。

 

 

 

本文參考鏈接:

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

發佈了287 篇原創文章 · 獲贊 10 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章