prom-client
prom-client copied to clipboard
How to use Counter/Gauge to filter metrics by properties?
Hi,
I'm pretty new to prometheus / prom-client and currently trying to use your package to create a small monitoring solution. This monitoring solution tracks so called 'messages' that are processed by some service.
I can query a so called MessageLog, which gives me an Array of the messages, their processing status and some more properties e.g.:
[{ "MessageGuid":1234, "Status":"FAILED", "IntegrationFlowName":"Some IFlow" }, { "MessageGuid":1235, "Status":"COMPLETED", "IntegrationFlowName":"Some IFlow" }, { "MessageGuid":1236, "Status":"FAILED", "IntegrationFlowName":"Some IFlow" }, { "MessageGuid":1237, "Status":"COMPLETED", "IntegrationFlowName":"Some other IFlow" } ...]
What I'd like to do, is to collect a metric of messages and their status and also be able to group them by their property "IntegrationFlowName" in a Grafana dashboard later.
So I thought of using Gauges / Counters and putting the status / IntegrationFlowName as labels, as the prometheus documentation points out, that the differentiation should be done by labels.
However, that's not possible in my opinion, because I'd then need to be able to register a metric with the same name (e.g. Message statuses) multiple times, which is forbidden by this library.
Alternatively I now gave each metric a status specific name (e.g. CompletedMessages) to solve this for the time being. Following this approach to be able to also filter by IntegrationFlowName, I'd need to statically define a metric name for each combination of status / IntegrationFlowName. As there is a high number of IntegrationFlows and 8 statuses, this would cause quite a lot of metric definitions to do.
Am I overlooking something regarding such dynamic metrics or is my requirement simply not possible with this package?
Appreciate your help :)
Thanks in advance Regards Jan
You'd only register one gauge/counter but set the value for each set of label values separately, something like:
const messageGauge = new Gauge({
name: "message_count",
help: "something",
labelNames: ["status", "integrationFlowName"]
})
// ...
messageGauge.set({status: "COMPLETED", integrationFlowName: "Some IFlow"}, 1)
Thanks, works like a charm :)