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/

总结

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

相关推荐
毒爪的小新19 分钟前
Docker基础命令
linux·运维·docker·容器·centos
碎梦归途17 小时前
Linux 软件安装方式全解(适用于 CentOS/RHEL 系统)
linux·运维·centos
啃火龙果的兔子17 小时前
CentOS 7.9 安装 宝塔面板
linux·运维·centos
刘俊辉个人博客20 小时前
简单配置RHEL9.X
linux·运维·windows·经验分享·centos·github·vim
啃火龙果的兔子1 天前
宝塔面板安装nodejs后,通过node -v获取不到版本号,报错node: command not found
linux·运维·centos
qq_312920111 天前
K8S上使用helm部署 Prometheus + Grafana
kubernetes·grafana·prometheus
Hey! Hey!1 天前
CentOS 7镜像源替换
linux·运维·centos
MyikJ3 天前
Java 面试实录:从Spring到微服务的技术探讨
java·spring boot·微服务·kafka·spring security·grafana·prometheus
藥瓿亭3 天前
Vim常用快捷键
linux·ubuntu·centos·vim
小峰编程3 天前
rsync服务的搭建
linux·运维·服务器·云原生·centos·服务搭建