其他分享
首页 > 其他分享> > Prometheus-黑盒探针-Blackbox_exporter

Prometheus-黑盒探针-Blackbox_exporter

作者:互联网

Prometheus黑盒监控

本文原文介绍出处:运维老兵Alex

什么是黑盒探针?

项目地址:
https://github.com/prometheus/blackbox_exporter/releases

本篇主要介绍Prometheus如何通过Blackbox_exporter 的探针检测功能,来实现对应用的外部监控。

一)、Blackbox_exporter 介绍:


image

二)、部署Blackbox_exporter

Github下载地址

wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz
tar xf blackbox_exporter-0.19.0.linux-amd64.tar.gz -C /opt
ln -s /opt/blackbox_exporter-0.19.0.linux-amd64 /opt/blackbox_exporter
[root@ops blackbox_exporter]#vim /usr/lib/systemd/system/blackbox_exporter.service
//写入启动文件
[Unit]
Description=blackbox_exporter Exporter
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/opt/blackbox_exporter/blackbox_exporter --config.file=/opt/blackbox_exporter/blackbox.yml
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=blackbox_exporter
[Install]
WantedBy=default.target

[root@ops blackbox_exporter]#systemctl restart blackbox_exporter.service
[root@ops blackbox_exporter]#systemctl status blackbox_exporter.service
[root@ops blackbox_exporter]#systemctl enable blackbox_exporter.service
[root@ops blackbox_exporter]# ss -lnt        //查看端口9115是否启动
State      Recv-Q Send-Q                      Local Address:Port                                     Peer Address:Port              
LISTEN     0      128                                     *:22                                                  *:*                  
LISTEN     0      128                                  [::]:22                                               [::]:*                  
LISTEN     0      16384                                [::]:9115                                             [::]:*                  
LISTEN     0      16384                                [::]:9090                                             [::]:*                  
LISTEN     0      16384                                [::]:9093                                             [::]:*                  
LISTEN     0      16384                                [::]:9094                                             [::]:*                  
LISTEN     0      80                                   [::]:3306                                             [::]:*                  

image

http://locakhost:9115

image

三)、配置Prometheus:

#http 配置
  - job_name: 'blackbox-http'         # 标签名

    metrics_path: /probe

    params:
      module: [http_2xx]
    static_configs:                  #静态组
      - targets:
        - https://www.163.com
        - https://www.baidu.com
        - http://192.168.117.128:3000
    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  #匹配的值
#icmp 配置
  - job_name: 'blackbox-icmp'
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets:
        - 192.168.117.128
        - 192.168.168.129
        labels:
          instance: node_status
          group: 'node'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 192.168.117.128:9115
#端口状态
  - job_name: 'blackbox-port'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets:
        - 192.168.117.128:3000
        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: 192.168.117.128:9115
添加完成后重启prometheus

四)、浏览器进行验证:

http://locakhost:9090/targets

image

五)、Grafana里进行验证:

image
image
image
image
image

标签:__,黑盒,blackbox,target,http,label,Prometheus,exporter,Blackbox
来源: https://www.cnblogs.com/yaoxinlei/p/15704073.html