centos操作系统上以service形式运行blackbox_exporter监控网页端口

文章目录


前言

记录一下centos操作系统上以简单的service形式运行blackbox_exporter监控网页端口的记录


一、blackbox_exporter是什么

Blackbox Exporter是Prometheus官方提供的黑盒监控解决方案之一。它允许用户通过HTTP、HTTPS、DNS、TCP、ICMP和gRPC等方式对网络端点进行探测,以检查服务的可用性、响应时间和性能等关键指标。

二、使用步骤

1.获取二进制文件

官网地址:

https://github.com/prometheus/blackbox_exporter/releases

https://prometheus.io/download/#memcached_exporter

我这里选择的是blackbox_exporter-0.25.0.linux-amd64.tar.gz版本

2.准备部署脚本

shell 复制代码
#!/bin/bash

set -e
tar -xvf ./blackbox_exporter-0.25.0.linux-amd64.tar.gz
if [ -d ./blackbox_exporter-0.25.0.linux-amd64/ ];then
  sudo cp ./blackbox_exporter-0.25.0.linux-amd64/blackbox_exporter /usr/local/bin/ && cp ./blackbox_exporter-0.25.0.linux-amd64/blackbox.yml /usr/local/bin/
else
  echo "请检查 blackbox_exporter 所在文件目录"
  exit 1
fi

sudo touch /usr/lib/systemd/system/blackbox_exporter.service
sudo chmod o+w /usr/lib/systemd/system/blackbox_exporter.service
sudo chmod o+x /usr/local/bin/blackbox_exporter

cat << EOF > /usr/lib/systemd/system/blackbox_exporter.service 
[Service]
User=$USER
Group=$USER
ExecStart=/usr/local/bin/blackbox_exporter --config.file=/usr/local/bin/blackbox.yml

[Install]
WantedBy=multi-user.target

[Unit]
Description=blackbox_exporter
After=network.target 
EOF

sudo systemctl daemon-reload
sudo systemctl start blackbox_exporter
sudo systemctl enable blackbox_exporter
sudo systemctl status blackbox_exporter
echo 'end success'

3.执行命令,进行部署

shell 复制代码
chmod +x blackbox-expoter-0.25.0.sh
./blackbox-expoter-0.25.0.sh

4.prometheus中增加需要监控页面的job信息

配置之后重启prometheus

yaml 复制代码
  - job_name: '150.2_web_port_status'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
    - targets: ['192.168.150.2:8097']
      labels:
        instance: '192.168.150.2'
        tags: 'seafile平台端口'
    - targets: ['192.168.150.2:8098']
      labels:
        instance: '192.168.150.2'
        tags: 'onlyoffice平台端口'
    - targets: ['192.168.150.2:8088']
      labels:
        instance: '192.168.150.2'
        tags: '禅道平台端口'
    - targets: ['harbor.XXX.XXX.XX:10002']
      labels:
        instance: '192.168.150.2'
        tags: 'harbor平台端口'
    - targets: ['192.168.150.2:10001']
      labels:
        instance: '192.168.150.2'
        tags: 'gitlab平台端口'
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 192.168.150.XX:9115

三、查看部署结果

Blackbox Exporter页面

prometheus界面

四、配置到grafana中

使用13659的dashboard

地址:https://grafana.com/grafana/dashboards/13659-blackbox-exporter-http-prober/

总结

简单记录一下,高阶功能有具体需求的时候再使用了。

相关推荐
爱敲代码的TOM2 天前
Prometheus+Grafana构建企业级监控方案
prometheus
hashiqimiya2 天前
centos配置环境变量jdk
linux·运维·centos
百锦再2 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame
Insist7532 天前
prometheus安装部署与alertmanager邮箱告警
linux·运维·grafana·prometheus
半梦半醒*3 天前
正则表达式
linux·运维·开发语言·正则表达式·centos·运维开发
SonOfWind03113 天前
CentOS搭建本地源
linux·运维·centos
小阳睡不醒3 天前
小白成长之路-部署prometheus监控平台
prometheus
过尽漉雪千山3 天前
Flink1.17.0集群的搭建
java·大数据·linux·flink·centos
二进制_博客4 天前
给CentOS的虚拟机扩容
linux·运维·centos
张3蜂4 天前
MongoDB BI Connector 详细介绍与使用指南(手动安装方式,CentOS 7 + MongoDB 5.0.5)
数据库·mongodb·centos