prometheus / jmx_exporter

A process for exposing JMX Beans via HTTP for Prometheus consumption
Apache License 2.0
3.02k stars 1.2k forks source link

Allow blacklisting of jvm metrics #696

Open udesaiitrs opened 2 years ago

udesaiitrs commented 2 years ago

Hello, I was hoping to understand why certain JVM metrics (java.lang:*) cannot be blacklisted/removed via configuration of the javaagent? The exporter should include these as there can be instances like in our case where we do not want the duplicate JVM metrics because they are collected by another application.

For example, the following should work but doesn't I believe:


blacklistObjectNames: 
  - "java.nio:*"
  - "java.lang:*"
udesaiitrs commented 2 years ago

I have found how there are many default exports registered: https://github.com/prometheus/jmx_exporter/blob/ca972bfe693cca03d3a0fac802968e33828a1dd9/jmx_prometheus_javaagent_java6/src/main/java/io/prometheus/jmx/JavaAgent.java#L30

I feel as though it would be a good option to implement a configuration option to allow these to be turned off (on by default), especially with the growing scenarios such as Kubernetes environments where all the extra metrics may not be needed.

Is this something that sounds plausible?

gmariette commented 1 year ago

will appreciate such feature to, to not spawn our Prom cluster with the jvm container metrics

dhoard commented 1 year ago

This sounds like a great enhancement. It would require changes to ...

https://github.com/prometheus/client_java/blob/main/simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/DefaultExports.java

... to allow unregistering the collectors to support dynamic configuration reloading.

dhoard commented 1 year ago

Or as an alternative not use DefaultExports.initialize(); but add configuration-specific options and call the underlying exports classes directly.

new BufferPoolsExports().register(registry);
new ClassLoadingExports().register(registry);
new CompilationExports().register(registry);
new GarbageCollectorExports().register(registry);
new MemoryAllocationExports().register(registry);
new MemoryPoolsExports().register(registry);
new StandardExports().register(registry);
new ThreadExports().register(registry);
new VersionInfoExports().register(registry);