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

相关推荐
RainbowSea16 分钟前
伙伴匹配系统(移动端 H5 网站(APP 风格)基于Spring Boot 后端 + Vue3 - 06
java·spring boot·后端
Keya25 分钟前
MacOS端口被占用的解决方法
前端·后端·设计模式
用户90967830694327 分钟前
Python 判断一个字符串中是否含有数字
后端
jakeswang29 分钟前
应用缓存不止是Redis!——亿级流量系统架构设计系列
redis·分布式·后端·缓存
RainbowSea31 分钟前
伙伴匹配系统(移动端 H5 网站(APP 风格)基于Spring Boot 后端 + Vue3 - 05
vue.js·spring boot·后端
污橘37 分钟前
Nginx反向代理Oracle
后端·程序员
紫穹39 分钟前
005.LangChain Model
后端
葡萄城技术团队1 小时前
六大缓存(Caching)策略揭秘:延迟与复杂性的完美平衡
后端
杨杨杨大侠1 小时前
05 - 上下文管理机制 📦
后端·workflow
杨杨杨大侠1 小时前
06 - 表达式引擎实现 🔍
后端·workflow