On 17.05.20 23:27, Alex Chaplianka wrote:
> 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"}
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] [email protected]
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/20200522152910.GS2326%40jahnn.