Newbie: filter metrics by label for sending to push gateway?

165 views
Skip to first unread message

andig

unread,
Jun 20, 2021, 4:15:40 AM6/20/21
to Prometheus Users
I need to collect anonymous HTTP statistics from user installations. For security reasons, I only want to collect metrics about HTTP requests for particular purpose, while having the entire set of metrics available locally.

I‘m wondering how to best achieve this:
A) have separate metrics per „exportable“ and „local“ and a bunch of if statement to determine if the metric should be updated or not
B) (preferred) have a mechanism of always updating the metrics and filter for exporting by label (e.g. I could have a CounterVec with a purpose label that I would export only if purpose was „public“).

I‘ve not found any filtering mechanism to implement B) though. 

What is a good approach to achieve the requirements?

andig

unread,
Jun 20, 2021, 4:25:30 AM6/20/21
to Prometheus Users
To be a little more clear about the idea in B)

Imagine I have „exportable“, „status“ and „host“ as labels. For the anonymous reporting case I‘d collect all the metrics that have „exportable“=„yes“ (or „purpose“=„export“ or whatever). I can see CounterVec has GetMetricsWith but returns a single Counter, not a filtered CounterVec, so filtering by a partial labels map doesn‘t seem supported?

Bjoern Rabenstein

unread,
Jul 7, 2021, 11:11:45 AM7/7/21
to andig, Prometheus Users
On 20.06.21 01:15, andig wrote:
> I need to collect anonymous HTTP statistics from user installations. For
> security reasons, I only want to collect metrics about HTTP requests for
> particular purpose, while having the entire set of metrics available
> locally.

What do you mean by "available locally"?

It sounds like you should expose all desired metrics normally and then
use metric relabel configs to drop metrics you don't want to ingest on
the Prometheus server, see
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs

If you want to push selected metrics to the Pushgateway, you can
register the desired collectors with a custom registry and push that
one. However, note that this sounds like you are using the Pushgateway
for something that it is not meant for.

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