Go Client - Get all counter vec label vales

24 views
Skip to first unread message

Alex Chaplianka

unread,
May 18, 2020, 2:27:28 AM5/18/20
to Prometheus Users
I have a CounterVec object, I'm looking for a way to get all of it's labelsets.

For example in the /metric endpoint I can see

my_metric{a="b",k="d"}
my_meric{a="c"}

How could get those labels?:
{a="b", k="d"}
{a="c"}

Bjoern Rabenstein

unread,
May 22, 2020, 11:29:15 AM5/22/20
to Alex Chaplianka, Prometheus Users
There is no easy way of doing this (which is deliberate – inspecting
internal state is not an intended part of the exposed interfaces).

But you can do the following:

Call the `Collect` method of the `CounterVec`. Then call the `Write`
method of each `Metric` collected. This gives you `dto.Metric`
structs, which have a `Label` field of type `[]*dto.LabelPair`, which
are the labels you are looking for.

Example of code using a similar approach (in this case to return the
value of a metric):
https://github.com/prometheus/client_golang/blob/v1.6.0/prometheus/testutil/testutil.go#L78

--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in
Reply all
Reply to author
Forward
0 new messages