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/

总结

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

相关推荐
程序员果子10 小时前
零拷贝:程序性能加速的终极奥秘
linux·运维·nginx·macos·缓存·centos
知识分享小能手14 小时前
CentOS Stream 9入门学习教程,从入门到精通,CentOS Stream 9 进程管理 —语法详解与实战案例(8)
linux·学习·centos
古城小栈15 小时前
为Gin应用添加 一双眼睛:Prometheus
prometheus·gin
子夜江寒15 小时前
MySQL 安装与配置指南(CentOS 7)
数据库·mysql·centos
哇哈哈&15 小时前
rabbitmq最简单的安装方法
linux·运维·centos
java_logo1 天前
MILVUS Docker 容器化部署指南
运维·人工智能·docker·容器·prometheus·milvus
装不满的克莱因瓶1 天前
【Java架构 搭建环境篇三】Linux安装Git详细教程
java·linux·运维·服务器·git·架构·centos
知识分享小能手2 天前
CentOS Stream 9入门学习教程,从入门到精通,CentOS Stream 9 磁盘存储管理 —语法详解与实战案例(7)
linux·学习·centos
云计算老刘2 天前
3.Shell 变量基础知识
chrome·正则表达式·centos·云计算
siriuuus2 天前
Redis 安装、多实例部署、主从复制及 Cluster 实践
数据库·redis·centos