Search code examples
prometheus

Prometheus INFO metrics with recording rules


How to generate custom INFO metrics with recording rules?

The only workaround for this we've found is to use absent and non_exist together so it creates a custom INFO metric.

e.g. recording rule named "networks_id" defined as:

absent(non_exist{network_id="1",network_name="Ethereum"})

will create series

networks_id{{network_id="1", network_name="Ethereum Mainnet"}

where "non_exists" is just a string for metric name we don't have scraped...

Is there a more common way to accomplish this with prometheus recording rules?


Solution

  • I believe your approach is the most common one for creating vectors with arbitrary labels.

    One alternative way might be using label_replace to add label you want:

    label_replace(vector(1), "label", "label_value", "", "")
    

    This is particularly useful when you want add label to something already present. But for completely artificial vectors approach with absent is usually preferred, due to it's conciseness (with label_replace, you'd need one call of function for each new label).