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

相关推荐
mCell8 分钟前
为什么我们需要 `.proto` 文件
后端·微服务·架构
mit6.82435 分钟前
[Meetily后端框架] AI摘要结构化 | `SummaryResponse`模型 | Pydantic库 | vs marshmallow库
c++·人工智能·后端
陈随易1 小时前
VSCode v1.102发布,AI体验大幅提升
前端·后端·程序员
生无谓1 小时前
什么是跨域,如何处理跨域
后端
Smilejudy1 小时前
极具特色的位置运算
后端
码出极致1 小时前
支付线上问题复盘的“5W”框架
后端
ezl1fe1 小时前
RAG 每日一技(三):不止文本,代码和Markdown如何优雅地分块?
后端
jack_yin1 小时前
手把手教你玩转 telegram-deepseek-bot 的 Admin 管理后台!
后端
浮游本尊1 小时前
Java学习第8天 - Spring框架入门与依赖注入
后端
bcbnb1 小时前
iOS App 安全加固实战:如何满足合规审计与选对加固工具
后端