向默认 Golang Prometheus 指标添加标签

sto*_*_41 6 http go prometheus

我目前正在用作github.com/prometheus/client_golang检索 Golang 应用程序指标的端点。它提供了许多开箱即用的默认数据集,例如:

go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 10
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.13.10"} 1
Run Code Online (Sandbox Code Playgroud)

我似乎在库中找不到任何向这些数据集添加标签的功能。由于我将在同一台计算机上运行许多此类应用程序,因此我需要添加标签来区分数据点。在图书馆有什么办法可以做到这一点吗client_golang

cam*_*amh 1

这些应用程序中的每一个都应作为单独的作业/实例由普罗米修斯抓取。它将添加job标签和一个instance标签,该标签还可以区分不同的流程(并允许您区分同一作业的多个实例)。

有关更多详细信息,请参阅https://prometheus.io/docs/concepts/jobs_instances/#automatically- generated-labels-and-time-series 。

您还可以使用重新标记规则来添加其他标签,具体取决于您发现应用程序的方式。如果您使用静态配置(https://prometheus.io/docs/prometheus/latest/configuration/configuration/#static_config),您可以在该配置中添加额外的区分标签。类似地file_sd_confighttps://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config