在普罗米修斯( prometheus )中,我们可以选择在作业的每一个度量中添加一个标签,
- job_name: 'your_job'
honor_labels: true
static_configs:
- targets:
- '127.0.0.1'
labels:
cluster: 'stage'我想在度量标准中添加标签,但使用服务程序。我正在使用黑匣子普罗米修斯操作员扫描一些网站。这就是我的服务监视器的样子。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackbox-exporter
app.kubernetes.io/version: 0.20.0
instance: primary
name: prometheus-blackbox-exporter-example.com
namespace: monitoring
spec:
endpoints:
- interval: 30s
metricRelabelings:
- action: replace
replacement: https://example.com
sourceLabels:
- instance
targetLabel: instance
- action: replace
replacement: example.com
sourceLabels:
- target
targetLabel: target
params:
module:
- http_2xx
target:
- https://example.com
path: /probe
port: http
scheme: http
scrapeTimeout: 30s
jobLabel: prometheus-blackbox-exporter
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackbox-exporter我想为这项工作中的指标添加一个标签。标签是
project: monitoring我如何使用服务程序来实现它呢?
发布于 2022-11-26 16:01:26
在spec.endpoints[].metricRelabelings或spec.endpoints[].relabelings下添加以下内容
- targetLabel: project # name
replacement: monitoring # value例如:
spec:
endpoints:
- interval: 30s
relabelings:
- targetLabel: project
replacement: monitoring在您的情况下,使用spec.endpoints[].relabelings的选项更好,因为标签不仅会出现在收集的指标上,而且也会出现在所有自动的(比如up)上。
阅读更多关于文档中重新标记的信息:https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
发布于 2022-11-30 22:22:01
要在Prometheus中使用ServiceMonitors向度量标准添加静态标签,可以在ServiceMonitor资源中使用static_configs字段。此字段允许您指定要刮除的目标列表及其相关标签。
下面是一个示例,说明如何使用static_configs字段将带有值monitoring的project标签添加到来自ServiceMonitor的度量中:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackbox-exporter
app.kubernetes.io/version: 0.20.0
instance: primary
name: prometheus-blackbox-exporter-example.com
namespace: monitoring
spec:
endpoints:
- interval: 30s
metricRelabelings:
- action: replace
replacement: https://example.com
sourceLabels:
- instance
targetLabel: instance
- action: replace
replacement: example.com
sourceLabels:
- target
targetLabel: target
params:
module:
- http_2xx
target:
- https://example.com
path: /probe
port: http
scheme: http
scrapeTimeout: 30s
static_configs:
- targets:
- https://example.com
labels:
project: monitoring
jobLabel: prometheus-blackbox-exporter
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackbox-exporter在上面的示例中,static_configs字段用于指定https://example.com的目标和project: monitoring的标签。这将导致Prometheus从https://example.com端点中刮取度量,并将project: monitoring标签应用于从该端点收集的所有度量。
发布于 2022-12-01 21:16:37
要将静态标签添加到由Prometheus中的ServiceMonitor监视的作业生成的度量中,可以在ServiceMonitor配置中使用job_label字段。
job_label字段指定一个标签,该标签将添加到由ServiceMonitor监视的作业生成的所有指标中。对于作业生成的所有指标,标签值都是相同的,因此您可以使用此字段添加应用于整个作业的静态标签。
下面是一个示例,说明如何在job_label配置中使用ServiceMonitor字段将静态标签添加到作业生成的指标中:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackbox-exporter
app.kubernetes.io/version: 0.20.0
instance: primary
name: prometheus-blackbox-exporter-example.com
namespace: monitoring
spec:
endpoints:
- interval: 30s
metricRelabelings:
- action: replace
replacement: https://example.com
sourceLabels:
- instance
targetLabel: instance
- action: replace
replacement: example.com
sourceLabels:
- target
targetLabel: target
params:
module:
- http_2xx
target:
- https://example.com
path: /probe
port: http
scheme: http
scrapeTimeout: 30s
jobLabel: project
jobName: monitoring
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app.kubernetes.io/instance: prometheus-blackbox-exporter
app.kubernetes.io/name: prometheus-blackhttps://stackoverflow.com/questions/74536514
复制相似问题