prometheus增加和删除labels
在Prometheus中,一个metric可以有多个label,label由key和value组成。
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
httpRequestCount = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "http_request_count",
Help: "The total number of http request",
},
[]string{"url", "is_success"},
)
)
// 增加label:基于标签来增加数量
httpRequestCount.WithLabelValues("http://127.0.0.1:80/test", "true").Inc()
// 删除label
httpRequestCount.DeleteLabelValues("http://127.0.0.1:80/test", "true")