prometheus / client_java

Prometheus instrumentation library for JVM applications
http://prometheus.github.io/client_java/
Apache License 2.0
2.17k stars 792 forks source link

Caffeine: allow specifying custom metric labels #603

Open aaabramov opened 3 years ago

aaabramov commented 3 years ago

Allow library users to specify custom labels for CacheMetricsCollector. Please upvote this issue if you would like this feature to be merged.


Let's say we are having k8s cluster with 10 different apps. Each of it uses caffeine as a cache. But single prometheus scrapper.

Currently, the only way to distinguish cache metrics provided by this library between apps is to modify somehow cacheName parameter (either we can prefix it with domain, e.g. users_the_cache_name, dashboards_the_cache_name, etc. or with postfix). This makes creating Grafana dashboards pretty difficult as we have to rely on regexes of cache label.

In order to create cache dashboard for users service we have to write something like

sum(rate(caffeine_cache_miss_total{cache~="users_.*"}[5m])) by (cache)

I think would be easier for users to specify their own labels and create Grafana dashboard like this:

Map<String, String> labels = new HashMap<String, String>() {{
    put("app", "users-service");
}};

CacheMetricsCollector coll = new CacheMetricsCollector(labels);
sum(rate(caffeine_cache_miss_total{app="users-service"}[5m])) by (cache)

NOTE: Implemented in scope of https://github.com/prometheus/client_java/pull/602 but has some drawbacks (see PR comments).

zorba128 commented 9 months ago

See #901 and #905 - same problem, other solution.