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/

总结

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

相关推荐
亦世凡华、7 小时前
快速部署:在虚拟机上安装 CentOS 7 的详细步骤
linux·运维·经验分享·centos·安装教程
北冥有鱼被烹1 天前
【微知】Centos如何迁移到Anolis系统的失败记录?(yum -y install centos2anolis、centos2anolis.py)
linux·服务器·centos
Eternity.,2 天前
【Git原理与使用三】Git远程仓库
git·gitee·centos·远程仓库
老大白菜2 天前
在CentOS系统上安装Conda的详细指南
linux·centos·conda
m0_748248232 天前
centOS 环境 安装redis方法
linux·redis·centos
我的ID配享太庙呀2 天前
Centos的ElasticSearch安装教程
运维·计算机网络·elasticsearch·centos·智能路由器·jenkins·es
encoding-console2 天前
k8s概念及k8s集群部署(Centos7)
云原生·容器·kubernetes·centos·部署
rockmelodies2 天前
CentOS 最新系统安装 Redis 7.0.11 详细指南
linux·redis·centos
卡西里弗斯奥2 天前
【CentOS】搭建Radius服务器
linux·服务器·centos·radius