Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add common tags to all my Prometheus Metrics using the Java Client

My Java application exposes Prometheus metrics. I want to add extra tags to each metric so when they are scraped I can use those tags in a query.

like image 741
checketts Avatar asked Jan 30 '23 01:01

checketts


1 Answers

The best way to add tags is to use the Prometheus service discovery. This keeps these tags out of your application code and keeps it from being concerned about where it exists.

However sometime if you absolutely need those extra tags (due to the service having extra insight that Prometheus service discovery isn't surfacing) you can't use the Java Simple Client (the Go client does support this though)

I turns out this feature is offered via a Micrometer feature called 'Common Tags' which wraps the Prometheus Java client. You setup your client so the tags are available via a config() call.

registry.config().commonTags("stack", "prod", "region", "us-east-1");
like image 161
checketts Avatar answered Feb 08 '23 14:02

checketts