Reputation: 2453
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?
Upvotes: 11
Views: 14559
Reputation: 2210
I would simply do it this way ->
// 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(collectors.NewGoCollector())
Upvotes: 4
Reputation: 41
This solution worked from me. Idea is to create a custom registry and register our metrics. Making sure we pass False
in handler options for open metrics will disable those default metrics
var httpDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "golang_api_http_duration_seconds",
Help: "Duration of HTTP requests.",
}, []string{"path", "host"})
promReg := prometheus.NewRegistry()
promReg.MustRegister(httpDuration)
handler := promhttp.HandlerFor(
promReg,
promhttp.HandlerOpts{
EnableOpenMetrics: false,
})
http.Handle("/metrics", handler)
log.Fatal(http.ListenAndServe(":12345", nil))
Upvotes: 4
Reputation: 1512
you can use --web.disable-exporter-metrics
now.
https://github.com/prometheus/node_exporter/pull/1148
Upvotes: 1
Reputation: 361
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))
}
Upvotes: 18
Reputation: 34112
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.
Upvotes: 1
Reputation: 2897
It's not really helpful as an answer to say "you'd have to go and do it yourself" but it seems like the only option for now.
Since Prometheus is open source and if you really need to do that; I believe you'd have to fork this one go_collector.go line #28 and the related sections, or better yet modify it to make all those metrics optional and make a PR so other people may also benefit from that in the future.
Upvotes: 0