kube-prometheus 使用 blackbox-exporter 进行TCP监控与 http 监控
本文最后更新于 715 天前,其中的信息可能已经有所发展或是发生改变。

kube-prometheus 使用 blackbox-exporter 进行TCP监控与 http 监控

前言

安装kube-prometheus 后默认在namespace的monitoring中有创建 blackbox-exporter的deployment。因此k8s中无需再部署blackbox-exporter

创建Probe资源

接下来,创建Probe资源来定义TCP和HTTP探测。可以使用以下YAML配置:

kind: Probe
apiVersion: monitoring.coreos.com/v1
metadata:
  name: tcp_example
  namespace: monitoring
spec:
  interval: 60s
  module: tcp_connect
  jobLabel: tcp_example
  prober:
    url: blackbox-exporter.monitoring.svc.cluster.local:19115
  targets:
    staticConfig:
      static:
        - ip:8443

---
kind: Probe
apiVersion: monitoring.coreos.com/v1
metadata:
  name: example-http
  namespace: monitoring
spec:
  interval: 60s
  module: http_2xx
  jobLabel: example-http
  prober:
    url: blackbox-exporter.monitoring.svc.cluster.local:19115
  targets:
    staticConfig:
      static:
        - http://ip:8443/test


使用以下命令应用Probe配置:

kubectl apply -f probe.yaml

检查Prometheus配置

确保Prometheus能够抓取到Probe的结果。可以在Prometheus的Web界面中查询probe_success指标,值为1表示探测成功,0表示失败。

image-20240903143559886

监控项

probe_

probe_success  #是否探测成功(取值1、0,分别表示成功、失败)
probe_duration_seconds #探测的耗时
#关于DNS
probe_dns_lookup_time_seconds #DNS解析的耗时
probe_ip_protocol #IP协议取值为4、6
probe_ip_addr_hash #IP地址的哈希值,用于判断IP是否变化
#关于HTTP
probe_http_status_code #HTTP响应的状态码,如果发生重定向,则取决于最后一次响应
probe_http_content_length #HTTP响应的body长度,单位bytes
probe_http_version #HTTP响应的协议版本,比如1.1
probe_http_ssl #HTTP响应是否采用SSL,取值 1、0
probe_ssl_earliest_cert_expiry #SSL证书过期时间,为Unix时间戳

创建触发告警规则

groups:
- name: Blackbox
  rules:
  - alert: 黑盒子探测失败报警
    expr: probe_success == 0
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: '黑盒子探测失败 {{ $labels.instance }}'
      description: "黑盒子探测失败,当前值{{ $value }}"
  - alert: 请求慢告警
    expr: avg_over_time(probe_duration_seconds[1m]) > 1
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: '请求慢 {{ $labels.instance }}'
      description: "请求时间操过1秒,值{{ $value }}"
  - alert: http状态码检测失败
    expr: probe_http_status_code <= 199 OR probe_http_status_code >= 400
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: 'http状态码检测失败{{ $labels.instance }}'
      description: "HTTP状态码非200-399,当前状态码为{{ $value }}"
  - alert: ssl证书即将到期
    expr: probe_ssl_earliest_cert_expiry - time() < 86400 *30
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: '证书即将到期 {{ $labels.instance }}'
      description: "SSL 证书在30天后到期,值{{ $value }}"    

参考

1.https://github.com/prometheus-operator/kube-prometheus/blob/release-0.9/docs/blackbox-exporter.md

2.https://blog.csdn.net/qq_31977125/article/details/132164695

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇