实战Prometheus-blackbox_exporter

简介: Prometheus-blackbox_exporter

7、blackbox_exporter 软件安装
bloackbox exporter是prometheus社区提供的黑盒监控解决方案,运行用户通过HTTP、HTTPS、DNS、TCP以及ICMP的方式对网络进行探测。这里通过blackbox对我们的站点信息进行采集。
官方下载地址:
https://github.com/prometheus/blackbox_exporter/releases/download/v0.18.0/blackbox_exporter-0.18.0.linux-amd64.tar.gz

# 解压文件
tar xf blackbox_exporter-0.18.0.linux-386.tar.gz
cd blackbox_exporter-0.18.0.linux-386/

# 配置启动文件
vim  /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/montion/blackbox_exporter-0.18.0.linux-386
ExecStart=/montion/blackbox_exporter-0.18.0.linux-386/blackbox_exporter
[Install]
WantedBy=multi-user.target


# 启动
[root@node00 system]# systemctl restart blackbox_exporter
# 查看状态
[root@node00 system]# systemctl status blackbox_exporter
# 开机自启
[root@node00 system]# systemctl enable blackbox_exporter
# 服务端口
 9115

2、Prometheus 中集成 blackbox_exporter

#修改配置文件
vim prometheus.yml
  - job_name: "blackbox"
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    file_sd_configs:
    - refresh_interval: 1m
      files:
      - "/montion/prometheus-2.19.1/conf/blackbox*.yml"
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: x.x.x.x:9115

# 添加配置
[root@harbor conf]# pwd
/montion/prometheus-2.19.1/conf
[root@harbor conf]# vim blackbox-dis.yml
- targets:
  - https://www.alibaba.com
  - https://www.tencent.com
  - https://www.baidu.com
  - http://x.x.x.x:9104/metrics
  
# 配置标签
- labels:
    role: 百度
  targets:
  - https://www.baidu.com
- labels:
    role: IP 地址
  targets:
  - https://1.2.5.6

  # nginx 案例
    - job_name: 'nginx'
    static_configs:
      - targets:
        - x.x.x.x:9913
        labels:
          app: nginx
          role: gateway
    metrics_path: /metrics
    scrape_timeout: 10s
    params:
      module: [huawei]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: x.x.x.x:9913  

# 重启服务
systemctl restart prometheus.service

# http tcp  icmp
  - job_name: "http-status"
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    file_sd_configs:
    - refresh_interval: 1m
      files:
      - "/opt/prometheus-2.19.1/blackbox/http.yml"
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: x.x.x.x:9115
# 模板 [root@SVR-Prometheus01 blackbox]# cat tcp.yml
       - labels: 
           role: 数据库 
         targets: 
        - x.x.x.x:3306 
  - job_name: "tcp-status"
    metrics_path: /probe
    params:
      module: [tcp_connect]  # Look for a HTTP 200 response.
    file_sd_configs:
    - refresh_interval: 1m
      files:
      - "/opt/prometheus-2.19.1/blackbox/tcp.yml"
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: x.x.x.x:9115
  
-------------------------------------------- 告警
# 证书告警
  - name: ssl_expiry.rules 
    rules: 
      - alert: SSLCertExpiringSoon 
        expr: probe_ssl_earliest_cert_expiry{job="blackbox"} - time() < 86400 * 30 
        for: 10m
# 接口故障告警
groups:
- name: node-export
  rules:
  - alert: "黑盒探测"
    expr: probe_success{job=~"blackbox"} == 0
    for: 1m
    labels:
      env: test
      app: test-1
    annotations:
      description: "{{ $labels.instance }} ({{ $labels.role }})接口故障,请及时进行检查,当前值:{{ $value }}"

3、grafana 配置
导入官方模板:
ID: 9965 13659 11529 11365
插件去官网安装安装在服务器执行
grafana-cli plugins install grafana-piechart-panel

相关文章
|
4月前
|
消息中间件 Prometheus 监控
Prometheus实战篇:什么是Exporter
所有可以向Prometheus提供监控样本数据的程序都可以被称为一个Exporter.而Exporter的一个实例称为target,如图下所示, Prometheus通过轮询的方式定期从这些target中获取样本数据
|
6月前
|
存储 Prometheus 监控
【Prometheus】什么是prometheus?prometheus简介
【Prometheus】什么是prometheus?prometheus简介
57 0
|
4月前
|
Prometheus 监控 Cloud Native
Prometheus
Prometheus 是一款开源的监控和报警工具,可以用于监控各种类型的组件,例如应用程序、数据库、网络设备等等。它通过收集和处理指标来提供有关系统状态的实时和历史视图,并通过报警机制来通知管理员当系统出现异常时。
65 1
|
5月前
|
Prometheus Cloud Native 网络安全
Prometheus+Grafana+Alertmanager部署教程(超详细)
Prometheus+Grafana+Alertmanager部署教程(超详细)
368 1
|
6月前
|
存储 Prometheus 监控
今天聊聊Prometheus
今天聊聊Prometheus
40 0
|
8月前
|
存储 Prometheus 监控
Prometheus入门
Prometheus入门
145 1
|
8月前
|
Prometheus Kubernetes Cloud Native
k8s安装prometheus
##### 安装 在目标集群上,执行如下命令: ```shell kubectl apply -f https://github.com/512team/dhorse/raw/main/conf/kubernetes-prometheus.yml ``` ##### 使用 1.在浏览器访问地址:http://master_ip:30000,如下图所示: 2.查看k8s自带的指标数据,如下图所示:
k8s安装prometheus
|
9月前
|
Prometheus 监控 Cloud Native
【2023】Prometheus-Blackbox_exporter使用
【2023】Prometheus-Blackbox_exporter使用
199 0
|
存储 Prometheus 监控
Exporter + Prometheus + Grafana进行监控
Exporter + Prometheus + Grafana进行监控
304 0
Exporter + Prometheus + Grafana进行监控