登录
首页 >  Golang >  Go问答

给 Golang Prometheus 指标增加附加信息

来源:stackoverflow

时间:2024-03-26 10:54:32 401浏览 收藏

在使用 client_golang 库检索 Go 应用程序指标时,无法直接向默认数据集添加标签。为了区分不同应用程序的数据点,建议将每个应用程序作为单独的作业由 Prometheus 抓取,这将自动添加 job 和 instance 标签。此外,可以使用重新标记规则或静态配置添加其他标签,以根据应用程序的发现方式进一步区分。

问题内容

我目前正在使用 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

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


解决方案


每个应用程序都应作为单独的作业/实例由普罗米修斯抓取。它将添加 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_config 类似:https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《给 Golang Prometheus 指标增加附加信息》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>