如何在prometheus / client_golang中禁用go_collector指标

mar*_*ark 2 monitoring go prometheus

我正在使用NewGaugeVec报告我的指标:

elapsed := prometheus.NewGaugeVec(prometheus.GaugeOpts{
    Name: "gogrinder_elapsed_ms",
    Help: "Current time elapsed of gogrinder teststep",
}, []string{"teststep", "user", "iteration", "timestamp"})
prometheus.MustRegister(elapsed)
Run Code Online (Sandbox Code Playgroud)

一切正常,但我注意到我的自定义导出器包含prometheus / go_collector.go中的所有指标:

# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00041795300000000004
go_gc_duration_seconds{quantile="0.25"} 0.00041795300000000004
go_gc_duration_seconds{quantile="0.5"} 0.00041795300000000004
...
Run Code Online (Sandbox Code Playgroud)

我怀疑这是一种默认行为,但是我没有在文档中找到如何禁用它的任何内容。关于如何配置自定义导出器以使这些默认指标消失的任何想法?

rje*_*ter 5

好了,这个话题已经很老了,但是如果其他人不得不处理这个话题的话。以下代码可以在当前代码库v0.9.0-pre1中正常运行

// [...] imports, metric initialization ...

func main() {
  // go get rid of any additional metrics 
  // we have to expose our metrics with a custom registry
  r := prometheus.NewRegistry()
  r.MustRegister(myMetrics)
  handler := promhttp.HandlerFor(r, promhttp.HandlerOpts{})

  // [...] update metrics within a goroutine

  http.Handle("/metrics", handler)
  log.Fatal(http.ListenAndServe(":12345", nil))
}
Run Code Online (Sandbox Code Playgroud)


bri*_*zil 1

目前这在 Go 客户端中是不可能的,一旦https://github.com/prometheus/client_golang/issues/46完成,您将有办法做到这一点。

一般来说,您希望自定义导出器导出这些,我知道目前没有意义的唯一导出器是 snmp 和 blackbox 导出器。

顺便说一句timestamp,作为一个标签似乎很奇怪,如果您愿意,您可能应该使用日志记录而不是指标。请参阅https://blog.raintank.io/logs-and-metrics-and-graphs-oh-my/ Prometheus 的方式是将时间戳作为值,而不是标签。