【问题标题】:How to disable go_collector metrics in prometheus/client_golang如何在 prometheus/client_golang 中禁用 go_collector 指标
【发布时间】:2016-05-09 03:56:12
【问题描述】:

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

一切正常,但我注意到我的自定义导出器包含来自 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
...

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

【问题讨论】:

    标签: go monitoring prometheus


    【解决方案1】:

    好吧,这个话题已经很老了,但以防其他人不得不处理它。 以下代码适用于当前代码库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))
    }
    

    【讨论】:

    • 刚刚验证这也适用于代码库的版本1.0.0
    【解决方案2】:

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

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

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

    【讨论】:

    • 嗯,如果我没记错的话,普罗米修斯声称不会固执己见……如果说我为我的盆栽植物维护了一个湿度传感器网络。我认为如果工厂报告其 goroutines 的数量、gc 统计信息等,这很奇怪。很高兴知道这已经开始了。感谢您的指标文章!
    • Prometheus 非常固执己见,因为很多乍一看似乎是个好主意的东西实际上是反模式。拥有所有关键系统指标很重要,这包括出口商本身的表现。通过刮擦自动获得它几乎总是正确的做法。盆栽植物的某些东西可能属于没有意义的类别,您应该根据确切的架构单独监控出口商。
    • 看起来该问题已完成,但仍然无法禁用它。那里有init()(Golang 称之为)无条件启动 Go 运行时和进程收集器:github.com/prometheus/client_golang/blob/…
    【解决方案3】:

    说“你必须自己去做”并没有真正的帮助,但它似乎是目前唯一的选择。

    由于 Prometheus 是开源的,如果你真的需要这样做;我相信您必须分叉 this onego_collector.go 第 28 行和相关部分,或者更好地对其进行修改以使所有这些指标成为可选并进行 PR,以便其他人将来也可以从中受益。

    【讨论】:

      【解决方案4】:

      我会这样做 ->

      // Register your collectors
      elapsed := prometheus.NewGaugeVec(prometheus.GaugeOpts{
          Name: "gogrinder_elapsed_ms",
          Help: "Current time elapsed of gogrinder teststep",
      }, []string{"teststep", "user", "iteration", "timestamp"})
      prometheus.MustRegister(elapsed)
      // Remove Go collector
      prometheus.Unregister(prometheus.NewGoCollector())
      

      【讨论】:

        【解决方案5】:

        您现在可以使用--web.disable-exporter-metrics

        https://github.com/prometheus/node_exporter/pull/1148

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-02
          • 2020-10-31
          • 2020-11-26
          • 2019-04-30
          • 1970-01-01
          相关资源
          最近更新 更多