How to turn off metric default of prometheus exporter

4,294 views
Skip to first unread message

vanti...@gmail.com

unread,
Jan 3, 2017, 10:31:46 PM1/3/17
to Prometheus Developers
Hi all,

I written prometheus exporter by golang

here is my code:

var (
nodeCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "service_status",
Help: "Soa manager service status.",
},
[]string{"venture", "service", "satus", "resource"},
)
)

func init() {
prometheus.MustRegister(nodeCounter)
}

It's work perfect but it show the default metric like this:

# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 7335
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 0
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 1.736704e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 0

But i don't want to show this, i only want to show my custom information

How can i do this?

thanks

Brian Brazil

unread,
Jan 4, 2017, 5:03:54 AM1/4/17
to vanti...@gmail.com, Prometheus Developers
For a normal exporter you should leave this information in place, as it helps debug the exporter itself.

If you're doing something like the blackbox/snmp exporter you'd be using a custom registry, which wouldn't have this by default.
 
--

Björn Rabenstein

unread,
Jan 4, 2017, 5:24:40 AM1/4/17
to Brian Brazil, vanti...@gmail.com, Prometheus Developers
On 4 January 2017 at 11:03, Brian Brazil
<brian....@robustperception.io> wrote:
>
> If you're doing something like the blackbox/snmp exporter you'd be using
> a custom registry, which wouldn't have this by default.

Relevant parts of the documentation for the above:
https://godoc.org/github.com/prometheus/client_golang/prometheus#hdr-Advanced_Uses_of_the_Registry
https://godoc.org/github.com/prometheus/client_golang/prometheus#Registry

--
Björn Rabenstein, Engineer
http://soundcloud.com/brabenstein

SoundCloud Ltd. | Rheinsberger Str. 76/77, 10115 Berlin, Germany
Managing Director: Alexander Ljung | Incorporated in England & Wales
with Company No. 6343600 | Local Branch Office | AG Charlottenburg |
HRB 110657B

Tín Huỳnh Văn

unread,
Jan 6, 2017, 5:35:20 AM1/6/17
to Prometheus Developers, brian....@robustperception.io, vanti...@gmail.com
do you have example for this?

Björn Rabenstein

unread,
Jan 6, 2017, 5:53:45 AM1/6/17
to Tín Huỳnh Văn, Prometheus Developers, Brian Brazil
On 6 January 2017 at 11:35, Tín Huỳnh Văn <vanti...@gmail.com> wrote:
> do you have example for this?

The test code has one:
https://github.com/prometheus/client_golang/blob/master/prometheus/promhttp/http_test.go#L46

You could also search for "prometheus.NewRegistry" on GitHub for more.

I'll work on improved documentation once the planned interface changes
have been determined.

quxi...@gmail.com

unread,
Jun 6, 2017, 7:08:47 AM6/6/17
to Prometheus Developers
you can use function "Unregister" to remove these default registries.

In github.com/prometheus/client_golang/prometheus/registry.go

func init() {
MustRegister(NewProcessCollector(os.Getpid(), ""))
MustRegister(NewGoCollector())
}

so, you can write code as below:

prometheus.Unregister(prometheus.NewProcessCollector(os.Getpid(), ""))
prometheus.Unregister(prometheus.NewGoCollector())

but, I can not remove http_request* metrics because it's the default behavior in prometheus.Handler()

Björn Rabenstein

unread,
Jun 6, 2017, 9:54:41 AM6/6/17
to quxi...@gmail.com, Prometheus Developers
On 6 June 2017 at 13:08, <quxi...@gmail.com> wrote:
>
> but, I can not remove http_request* metrics because
> it's the default behavior in prometheus.Handler()

Use prometheus.UninstrumentedHandler(), or, even better, promhttp.Handler().

屈啸 (Xavier)

unread,
Jun 6, 2017, 11:17:54 PM6/6/17
to Björn Rabenstein, Prometheus Developers
Thanks for the tip! 
Reply all
Reply to author
Forward
0 new messages