You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When registering a new metric with JmxReporter the name is generated via com.codahale.metrics.jmx.ObjectNameFactory which might be slightly different between versions.
server.isRegistered(new ObjectName("metrics:name=" + metricKey)) // returns false
server.isRegistered(new ObjectName("metrics:name=" + metricKey + ",type=counters")) // returns true when registered metric is a counter
com.codahale.metrics.jmx.ObjectNameFactory is package private in JmxReporter, but can provide custom one with a domain name via com.codahale.metrics.jmx.JmxReporter.Builder#Builder.
Unfortunately you also need to know the metric types which are hardcoded in the implementation (see usages of com.codahale.metrics.jmx.JmxReporter.JmxListener#createName).
String domain = "metrics";
ObjectNameFactory objectNameFactory = new DefaultObjectNameFactory();
MetricRegistry registry = new MetricRegistry();
JmxReporter reporter = JmxReporter.forRegistry(registry).createsObjectNamesWith(objectNameFactory).inDomain(domain).build();
reporter.start();
String metricKey = "metric.key";
registry.register(metricKey, new Counter());
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
System.out.println(server.isRegistered(objectNameFactory.createName("counters", domain, metricKey)));
Hi. I am using the latest
metrics-jmx (4.2.12)
library.Here is a snippet of my code
Initialize the metrics registry:
Register metrics:
Get the count using
ManagementFactory.getPlatformMBeanServer()
The issue is it says that the metric is not registered i.e
server.isRegistered(metric)
returnsfalse
.This works with
metrics-jmx (4.0.7)
but notmetrics-jmx (4.1.0)
Can someone help me if I need to do something else to achieve this? or is it an issue in the library?
The text was updated successfully, but these errors were encountered: