Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http 向默认的Golang Prometheus度量添加标签_Http_Go_Prometheus - Fatal编程技术网

Http 向默认的Golang Prometheus度量添加标签

Http 向默认的Golang Prometheus度量添加标签,http,go,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

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

似乎我在库中找不到任何向这些数据集添加标签的功能。因为我将在同一台机器上运行许多这样的应用程序,所以我需要添加标签来区分数据点。在
客户端_golang
库中有什么方法可以做到这一点吗?

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

有关更多详细信息,请参阅


您还可以使用重新标记规则添加其他标签,具体取决于您发现应用程序的方式。如果您使用的是静态配置(),则可以在该配置中添加额外的差异化标签。类似地,对于
文件\u sd\u config

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

有关更多详细信息,请参阅


您还可以使用重新标记规则添加其他标签,具体取决于您发现应用程序的方式。如果您使用的是静态配置(),则可以在该配置中添加额外的差异化标签。类似地,对于
文件\u sd\u config

有一个添加常量标签的选项。例如:

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

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

有一个选项可以添加常量标签。例如:

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

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