如何标记 Prometheus blackbox_exporter 端点
Posted
技术标签:
【中文标题】如何标记 Prometheus blackbox_exporter 端点【英文标题】:how to label Prometheus blackbox_exporter endpoints 【发布时间】:2021-03-26 01:10:15 【问题描述】:我有一个带有 Prometheus 的 k8s 集群和一些带有 Web 应用程序的 Pod。我想从这些网络应用程序中收集指标。我为此使用Prometheus blackbox_exporter。
我配置了服务监视器,部署,由 prometheus 操作员工作。 Prometheus 收集指标,但我无法区分它们。例如,probe_successendpoint="http-metrics",instance="10.20.0.105:9115",job="prometheus-blackbox-exporter",namespace="staging",pod="prometheus-blackbox-exporter-66fb58ff97-pd6lk",service="prometheus-blackbox-exporter"
我应该怎么做才能为每个端点添加额外的标签?
如何将 target 等标签添加到 probe_success 指标?
blackbox.yaml: |
modules:
http_2xx:
prober: http
http:
preferred_ip_protocol: "ipv4"
tls_config:
ca_file: "/config/my.pem"
http_post_4xx:
prober: http
http:
method: POST
valid_status_codes: [400,404,401,403]
headers:
Content-Type: application/json
body: '"nonsense"'
preferred_ip_protocol: "ipv4"
tls_config:
ca_file: "/config/my.pem"
服务是
---
kind: Service
apiVersion: v1
metadata:
name: prometheus-blackbox-exporter
labels:
app.kubernetes.io/name: prometheus-blackbox-exporter
name: prometheus-blackbox-exporter
monitoring: "true"
spec:
type: ClusterIP
ports:
- name: http-metrics
port: 9115
protocol: TCP
selector:
app.kubernetes.io/name: prometheus-blackbox-exporter
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: prometheus-blackbox-exporter
labels:
spec:
selector:
matchLabels:
name: prometheus-blackbox-exporter
endpoints:
- port: http-metrics
metricRelabelings:
- sourceLabels: [__address__]
targetLabel: __param_target
- sourceLabels: [__param_target]
targetLabel: instance
- sourceLabels: [__address__]
replacement: prometheus-blackbox-exporter:9115
path: /probe
params:
target:
- "web:3000"
module:
- "http_2xx"
- port: http-metrics
metricRelabelings:
- sourceLabels: [__address__]
targetLabel: __param_target
- sourceLabels: [__param_target]
targetLabel: instance
- sourceLabels: [__address__]
replacement: prometheus-blackbox-exporter:9115
path: /probe
params:
target:
- "api:8080/api/v1/login"
module:
- "http_post_4xx"
【问题讨论】:
【参考方案1】:想通了:
port: snmp-exporter
params:
module:
- if_mib # Select which SNMP module to use
target:
- 192.168.0.0
path: "/snmp"
targetPort: 9116
honorLabels: true
relabelings:
#- action: labelmap
- sourceLabels: [__param_target]
#regex: '.*'
#action: replace
targetLabel: instance
【讨论】:
以上是关于如何标记 Prometheus blackbox_exporter 端点的主要内容,如果未能解决你的问题,请参考以下文章
如何找到 helm 配置的 prometheus blackbox exporter 容器正在抓取的目标
具有端点身份验证的 Prometheus blackbox-exporter?
通过 API(Prometheus)以编程方式将目标添加到 Blackbox Exporter [关闭]