Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable go_collector metrics in prometheus/client_golang

I am using a NewGaugeVec to report my metrics:

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

All works fine but I noticed that my custom exporter contains all metrics from 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
...

I suspect that this is kind of a default behavior but I did not find anything in the documentation on how to disable that. Any ideas on how to configure my custom exporter so that these default metrics disappear?

like image 585
moin moin Avatar asked Jan 31 '16 18:01

moin moin


2 Answers

Well the topic is rather old but in case others have to deal with it. The following code works fine with current codebase 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))
}
like image 167
Ruben Jenster Avatar answered Sep 22 '22 14:09

Ruben Jenster


This is not currently possible in the Go client, once https://github.com/prometheus/client_golang/issues/46 is complete you'll have a way to do this.

In general you want your custom exporter to export these, the only ones I'm aware of where it doesn't currently make sense are the snmp and blackbox exporter.

Incidentally timestamp seems odd as a label, if you want that you should likely be using logging rather than metrics. See https://blog.raintank.io/logs-and-metrics-and-graphs-oh-my/ The Prometheus way would be to have the timestamp as a value, not as a label.

like image 29
brian-brazil Avatar answered Sep 21 '22 14:09

brian-brazil