Replies: 4 comments
-
You should init a registry first package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
)
func main() {
reg := prometheus.NewRegistry()
reg.MustRegister(collectors.NewGoCollector(
collectors.WithGoCollections(collectors.GoRuntimeMetricsCollection),
))
reg.Gather()
} |
Beta Was this translation helpful? Give feedback.
-
I understand I could create a separate registry, but it still seems incorrect that registering to the default should be causing a duplicate metric panic when I've requested only to register new runtime/metrics metrics. i.e., I would expect this to be additive only. |
Beta Was this translation helpful? Give feedback.
-
GoCollector has been registered to default registry when init, you can't register again |
Beta Was this translation helpful? Give feedback.
-
Hey @kjgorman, thanks for asking. I think @rogerogers has answered your question. Maybe it's not clear from the message, you're trying to register already registered metrics again. As mentioned above, by default GoCollector is registered to the default registry. You can also find an example over here https://github.com/prometheus/client_golang/blob/main/examples/gocollector/main.go |
Beta Was this translation helpful? Give feedback.
-
Hi there - I'm interested in attempting to enable the new
runtime/metrics
collector included in this package.I can't quite see how to actually get this to work though - I was expecting to need to do something like this:
but this panics with a duplicate metric:
it seems related to the collector registered in an
init
function, here. (i.e., by removing that collector registration, mine works inmain.main
).This reproduces at the most recent tagged version:
is this a bug or am I holding it wrong?
Beta Was this translation helpful? Give feedback.
All reactions