这是我的代码示例。现在我想在代码中添加直方图。
但我找不到一种方法来添加这样的直方图。
有人能帮我吗?
我可以写直方图样本,但我不能添加到我下面的代码
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"net/http"
)
type fooCollector struct {
fooMetric *prometheus.Desc
}
func newFooCollector(label1 string) *fooCollector {
return &fooCollector{
fooMetric: prometheus.NewDesc("fff_metric",
"Shows whether a foo has occurred in our cluster",
nil, prometheus.Labels{"env":label1},
),
}
}
func (collector *fooCollector) Describe(ch chan<- *prometheus.Desc) {
//Update this section with the each metric you create for a given collector
ch <- collector.fooMetric
}
func (collector *fooCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(collector.fooMetric, prometheus.GaugeValue, 111111)
}
func main() {
prometheus.MustRegister(newFooCollector("dev"))
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":80", nil)
}
2条答案
按热度按时间ezykj2lf1#
最后我知道了直方图works.here是我的代码
yc0p9oo02#
您只需为每个指标调用.Collect(ch)方法(其中包括描述和值),而且您不需要扩展默认的prometheus路由处理程序-只需小心,不要与默认指标名称冲突