8.prometheus远端探测监控-blackbox_exporter

一、远端探测介绍

监控应用程序的两种主要方法:探测和内省(例:node_exporter)。
探测监视应用程序的外部,可以查询应用程序的外部特征:是否响应开放端口上的轮询并返回正确的数据或响应代码?eg:执行ICMP ping或echo检查并确认是否收到了响应。这种类型的探测也称为黑盒探测,将内部应用程序视为黑盒。
Prometheus探测工作是通过blackbox_exporter 来探测远程目标,并公开在本地端点上收集的任何时间序列。然后,Prometheus从端点中提取指标。
 
探测有三个限制:
  • 能到到达探测的资源池
  • 探测的位置能够访问到应用程序资源的正确路径。
  • 探测exporter的位置能够被prometheus-server scape。

二、远端探测配置blackbox_exporter

1、概述

blackbox_exporter是一个二进制Go应用程序,默认监听端口9115。exporter允许通过HTTP、HTTPS、DNS、TCP和ICMP探测端点。在exporter中,我们定义一系列执行特定检查的模块,例:检查正在运行的web服务器,或者DNS解析记录。当exporter运行时,它会在URL上公开这些模块和API。

2、安装配置

安装配置blackbox_exporter
[root@master soft]# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
[root@master soft]# tar xf blackbox_exporter-0.16.0.linux-amd64.tar.gz
[root@master soft]# mv blackbox_exporter-0.16.0.linux-amd64 /opt/prometheus/blackbox_exporter
[root@master blackbox_exporter]# vim blackbox.yml  #只添加简单检测,更多配置参考官方文档
modules:
  http_2xx:
    prober: http
    timeout: 5s
    http:
      valid_status_codes: []
      method: GET
  icmp_check:
    prober: icmp
    timeout: 5s
    icmp:
      preferred_ip_protocol: "ipv4"
  dns_examplecom_check:
    prober: dns
    dns:
      preferred_ip_protocol: "ipv4"
      query_name: "baidu.com"
[root@master blackbox_exporter]# nohup ./blackbox_exporter --config.file="prober.yml" &
浏览器访问: http://192.168.42.128:9115/ 可以看到指标
prometheus配置添加一个job
[root@node1 prometheus]# vim prometheus.yml 
 ......
- job_name: black_exporter
    metrics_path: /probe
    params:
      modules: [http_2xx_check]
    static_configs:
      - targets:
        - 192.168.42.128:9115
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.42.128:9115
[root@node1 prometheus]# docker restart prometheus-server
访问prometheus web页面,可以看到已经检测了。
查看metric:
访问blackbox_exporter的web页面,也可以看到Recent Probes。
 

猜你喜欢

转载自www.cnblogs.com/cmxu/p/12294622.html