Prometheus业务监控 blackbox_exporter 部署与使用 – 21运维
通知: .-...

Prometheus业务监控 blackbox_exporter 部署与使用

prometheus 21运维 7873浏览

一,介绍
blackbox_exporter: Prometheus 官方提供的 exporter 之一,可以提供 http、https、dns、tcp、icmp 的监控数据采集
参考官方github: https://github.com/prometheus/blackbox_exporter
Blackbox_exporter 应用场景
(1)http/https测试
定义 Request Header 信息
判断 Http status / Http Respones Header / Http Body 内容
(2)tcp 测试 业务端口是否监听存活
(3)icmp 测试 主机探活、网络抖动监控
(3)POST 测试 接口联通性 、SSL证书过期时间等

二,安装部署
1,到prometheus官网直接下载安装包并用supervisor设置守护即可。
常用命令参数:

--config.file="blackbox.yml" # 默认配置文件,一般默认就可以,基本无需更改 
--web.listen-address=":9115" # 默认监听端口

2,使用supervisor守护启动:

[root@cn-hz-21yunwei-devops supervisord.d]# cat prome_black_exporter.conf 
[program:prome_blackbox_exporter]
command=/usr/local/prometheus/blackbox_exporter/blackbox_exporter
directory=/usr/local/prometheus/blackbox_exporter
stdout_logfile=/logs/prometheus/blackbox_exporter.log
autostart=true
autorestart=true
redirect_stderr=true
user=root
startsecs=3

reload以后,可以通过http://ip:9115/ 查看:

三,应用
通过配置prometheus.yml配置文件进行应用,比如之前设定的可以参考:

#判断告警搜 probe_success
## tcp端口检测
  - job_name: "tcp_port_check"
    scrape_interval: 15s
    scrape_timeout: 15s
    metrics_path: /probe
    params:
      module: [tcp_connect]
    file_sd_configs:
    - files:
      - check/port/*_port.json
 
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: ******:9115
 
## 判断状态码搜 probe_http_status_code
## 接口检测
  - job_name: 'http_url_check'
    scrape_interval: 15s
    scrape_timeout: 15s
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
 
    file_sd_configs:
    - files:
      - check/url/*_url.json    
 
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: *******:9115  
 
### ICMP检测
  - job_name: 'icmp_check'
    scrape_interval: 15s
    scrape_timeout: 15s
    metrics_path: /probe
    params:
      module: [icmp]
 
    file_sd_configs:
    - files:
      - check/icmp/*_icmp.json
 
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: ******:9115

说明:
(1)设定业务监控工具,比如这里的ip:915
(2)报警对象通过文件设定,这样不用每次重启prometheus守护。
(3)报警规则 由之前的rule下的规则设定。
(4)报警实现是通过alertmanager设定。

其中一个port检测的json文件这里记录一下:

[root@cn-hz-21yunwei-devops check]# cat port/linux_port.json  | jq 
[
  {
    "targets": [
      "127.0.0.1:80"
    ],
    "labels": {
      "group": "21yunwei",
      "hostname": "cn-hz-21yunwei-devops"
    }
  }
]

转载请注明:21运维 » Prometheus业务监控 blackbox_exporter 部署与使用