Prometheus blackbox exporter实现端口监控

修改Prometheus配置文件如下

yaml 复制代码
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "node-exporter"
    static_configs:
      - targets: ["192.168.202.221:9100","192.168.202.222:9100","192.168.202.223:9100","192.168.202.224:9100"]
  - job_name: "http_status"
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets: ["http://www.bing.com","https://www.baidu.com","https://www.jd.com"]
        labels:
          instance: http_status
          group: web
    relabel_configs:
      - source_labels: [__address__]  # relabel通过将__address__(当前目标地址)写入__param_target标签来创建一个label
        target_label: __param_target  # 监控目标http://www.bing.com,值为__address__的值
      - source_labels: [__param_target]  # 监控目标
        target_label: url              # 将监控目标与url创建一个label,此处的url值为__param_target里面的值
      - target_label: __address__
        replacement: 192.168.202.221:9115  # 写blackbox地址
  - job_name: "ping_status"
    metrics_path: /probe
    params: 
      module: [icmp]
    static_configs:
      - targets: ["192.168.202.221","192.168.202.222","192.168.202.223","192.168.202.224"]
        labels:
          instance: "ping_status"
          group: "icmp"
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: ip
      - target_label: __address__
        replacement: 192.168.202.221:9115
  - job_name: "port_status"
    metrics_path: /probe
    params:
      module: [tcp_connect]  # 检测端口
    static_configs:
      - targets: ["192.168.202.222:80","192.168.202.223:22","192.168.202.224:22"]
        labels:
          instance: "port_status"
          group: "port"
    relabel_configs:
     - source_labels: [__address__]
       target_label: __param_target
     - source_labels: [__param_target]
       target_label: ip
     - target_label: __address__
       replacement: 192.168.202.221:9115

检查配置文件正确性

sh 复制代码
root@node1:/usr/local/prometheus# ./promtool check config prometheus.yml 
Checking prometheus.yml
 SUCCESS: prometheus.yml is valid prometheus config file syntax

重启Prometheus

sh 复制代码
systemctl restart prometheus

查看结果

查看blackbox exporter

相关推荐
Ivanqhz28 分钟前
现代异构高性能计算(HPC)集群节点架构
开发语言·人工智能·后端·算法·架构·云计算·边缘计算
Loo国昌30 分钟前
【大模型应用开发】第三阶段:深度解析检索增强生成(RAG)原理
人工智能·后端·深度学习·自然语言处理·transformer
Demon_Hao43 分钟前
Spring Boot开启虚拟线程ScopedValue上下文传递
java·spring boot·后端
小高Baby@1 小时前
ShouldBind、ShouldBindJson、ShouldBindQuery的区别
后端·golang
BYSJMG1 小时前
计算机毕设选题推荐:基于Hadoop的交通事故数据可视化分析系统
大数据·vue.js·hadoop·分布式·后端·信息可视化·课程设计
野犬寒鸦1 小时前
从零起步学习并发编程 || 第三章:JMM(Java内存模型)详解及对比剖析
java·服务器·开发语言·分布式·后端·学习·spring
沐泽__1 小时前
Flask简介
后端·python·flask
半聋半瞎1 小时前
Flowable快速入门(Spring Boot整合版)
java·spring boot·后端·flowable
毕设源码-邱学长2 小时前
【开题答辩全过程】以 基于SpringBoot的理工学院学术档案管理系统为例,包含答辩的问题和答案
java·spring boot·后端
修己xj2 小时前
SpringBoot解析.mdb文件实战指南
java·spring boot·后端