安装blackbox_exporter

安装blackbox_exporter

上传监控软件

cd /opt/ ;scp [email protected]:/opt/blackbox_exporter-0.16.0.linux-amd64.tar.gz /opt

解压操作
[root@gtcq-gt-monitor-prometheus-01 opt]# tar -zxvf  blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
blackbox_exporter-0.16.0.linux-amd64/
blackbox_exporter-0.16.0.linux-amd64/LICENSE
blackbox_exporter-0.16.0.linux-amd64/NOTICE
blackbox_exporter-0.16.0.linux-amd64/blackbox_exporter
blackbox_exporter-0.16.0.linux-amd64/blackbox.yml
[root@gtcq-gt-monitor-prometheus-01 opt]# cd /usr/local/
[root@gtcq-gt-monitor-prometheus-01 local]# mv  blackbox_exporter-0.16.0.linux-amd64 blackbox_exporter
设置systemctl启动程序
[root@localhost ~]# vi /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \
    --config.file=/usr/local/blackbox_exporter/blackbox.yml \
    --web.listen-address=:9115
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart blackbox_exporter
[root@localhost ~]# netstat -tlunp | grep blackbox_expo
tcp6       0      0 :::9115              :::*              LISTEN      11925/blackbox_expo
设置blackbox_exporter配置文件
[root@gtcq-gt-monitor-prometheus-01 local]# cd blackbox_exporter/
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# ls
blackbox_exporter  blackbox.yml  LICENSE  NOTICE
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# cp blackbox.yml blackbox.yml.bak
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# > blackbox.yml
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# vim blackbox.yml
modules:
  http_2xx:  # http 监测模块
    prober: http
    http:
  http_post_2xx: # http post 监测模块
    prober: http
    http:
      method: POST
  tcp_connect: # tcp 监测模块
    prober: tcp
  ping: # icmp 检测模块
    prober: icmp
    timeout: 5s
    icmp:
      preferred_ip_protocol: "ip4"
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# 
[root@gtcq-gt-monitor-prometheus-01 blackbox_exporter]# systemctl restart blackbox_exporter
prometheus配置ping监测
vim prometheus.yml中添加如下内容
  - job_name: "主机网络监测"
    metrics_path: /probe
    params:
      module: [ping]
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - "/usr/local/prometheus/ping_host/ping_status*.yml"
    relabel_configs:
    - source_labels: [__address__]
      regex: (.*)(:80)?
      target_label: __param_target
      replacement: ${1}
    - source_labels: [__param_target]
      target_label: instance
    - source_labels: [__param_target]
      regex: (.*)
      target_label: ping
      replacement: ${1}
    - source_labels: []
      regex: .*
      target_label: __address__
      replacement: 127.0.0.1:9115 #此处是black_exporter和prometgeus关联的地方

创建ping_status.yml文件

[root@codeversionforgitserver ping_host]# more  ping_status.yml
- targets: ['192.168.11.165','10.2.2.32','10.2.2.35','10.2.2.36','10.2.2.37','10.2.2.95','10.2.2.96','10.1.32.25','10.1.32
.26','10.1.32.38','10.1.32.150','10.1.32.151','10.1.32.152','10.1.32.173','192.168.11.195','10.2.2.101','10.2.2.103','10.2
.2.104','10.2.2.105','10.1.32.142','10.1.32.143','10.1.32.144','10.1.32.145','10.1.32.146','10.2.2.106','10.2.2.107','10.2
.2.108','10.2.2.109']
  labels:
    group: '移动门户-网络PING监控'
- targets: ['10.1.32.46','10.1.32.46']
  labels:
    group: 'TIM-网络PING监控'
- targets: ['10.1.32.59','10.1.32.70','10.1.32.66','10.1.32.67','10.1.32.61','10.1.32.62','10.1.32.63','10.1.32.64','10.1.
32.68','10.1.32.69','10.2.1.120']
  labels:
    group: '门户PORTAL-网络PING监控' 
[root@codeversionforgitserver ping_host]# 

此时prometheus配置ping监测完成;
检查是否成功
访问prometheus
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tw7DSml4-1602932670024)(http://10.152.160.36/server/index.php?s=/api/attachment/visitFile/sign/342b65a9f43781fe61f0bc99d7d6c5a7&showdoc=.jpg)]

点击会出一个链接地址,访问此地址(注意&需要转义)通过配置文件可以很直接的看出Prometheus使用black_exporter作为代理使用black_exporter配置的module检测各个target的状态
[root@codeversionforgitserver ping_host]# curl http://codeversionforgitserver:9115/probe?module=ping\&target=10.1.32.142

猜你喜欢

转载自blog.csdn.net/qq_31555951/article/details/109136823