簡體   English   中英

為默認 Golang Prometheus 指標添加標簽

[英]Adding labels to the default Golang Prometheus metrics

我目前正在使用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庫中有什么方法可以做到這一點嗎?

這些應用程序中的每一個都應由 prometheus 作為單獨的作業/實例進行抓取。 它將添加job label 和instance label ,這也可以區分不同的進程(並允許您區分同一作業的多個實例)。

有關詳細信息,請參閱https://prometheus.io/docs/concepts/jobs_instances/#automatically-generated-labels-and-time-series

您還可以使用重新標記規則來添加其他標簽,具體取決於您發現應用程序的方式。 如果您使用的是 static 配置( https://prometheus.io/docs/prometheus/latest/configuration/configuration/#static_config ),您可以在該配置中添加額外的差異化標簽。 對於file_sd_config類似: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config

有一個選項可以添加常量標簽。 例如:

var (
    labels = map[string]string{"application": "foobar"}

    // Status Metrics
    StateCalls = prometheus.NewCounter(prometheus.CounterOpts{
        Name:        "state_calls",
        Help:        "",
        ConstLabels: labels,
    })
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM