prometheus - 如何标记 Prometheus blackbox_exporter 端点
问题描述
我有一个带有 Prometheus 的 k8s 集群和一些带有 Web 应用程序的 Pod。我想从这些网络应用程序中收集指标。我为此使用了Prometheus blackbox_exporter。
我配置了服务监视器,部署,由普罗米修斯操作员工作。Prometheus 收集指标,但我无法区分它们。例如,
probe_success{endpoint="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"
解决方案
弄清楚了:
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
推荐阅读
- listview - 颤动 listView.Builder 隐藏最后一个列表项的分隔符
- java - 避免增加 gridbag 布局网格空间的大小
- azure-functions - 您在哪里可以找到 Azure 功能的应用程序 ID/租户 ID?
- ios - iPhone XS Max 不调整原生组件高度
- python - Odoo 10 - Api.multi 装饰不会循环到所有记录
- javascript - 使用 Vue.js 向 Laravel 发送多个文件
- android - 如何在 FireStore Android 中一次更新和添加多个文档的数据?
- javascript - 对 html 和 javascript 的怀疑
- c++ - 如何打印对象向量?
- c# - 在网络服务器 c# 控制台应用程序上运行 exe