http - 将标签添加到默认的 Golang Prometheus 指标

标签 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

我似乎无法在库中找到任何向这些数据集添加标签的功能。因为我将在同一台机器上运行许多这样的应用程序,所以我需要添加标签来区分数据点。在 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

关于http - 将标签添加到默认的 Golang Prometheus 指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61985691/

相关文章:

java - 如何使用 reSTLet 从 jax-rs 获取客户端的 ip

Apache:摆脱 header 列表中的 Keep-Alive 条目

go - 从指针接口(interface)获取结构体的大小

prometheus - 普罗米修斯中的增加()有时会将值加倍 : how to avoid?

kubernetes - 通过Prometheus监控kubernetes服务或部署

php - 不使用 CURL 发送 GET 请求

multithreading - Play Framework Scala 线程亲和性

json - 使用标准模板包从json对象获取前两个值

go - 如何让gocolly爬得更慢

centos - 在没有 API 的情况下删除 prometheus 中的时间序列