use of org.springside.modules.metrics.exporter.JmxExporter in project springside4 by springside.
the class MetricExamples method jmxExample.
@Test
public void jmxExample() throws InterruptedException, Exception {
MetricRegistry metricRegistry = new MetricRegistry();
Counter counter = metricRegistry.counter(MetricRegistry.name("UserService", "getUser.counter"));
Timer timer = metricRegistry.timer(MetricRegistry.name("UserService", "getUser.timer"), new Double[] { 0.99d, 0.999d });
// 无reporter,only exporter
JmxExporter jmxExporter = new JmxExporter("metrics-example", metricRegistry);
jmxExporter.initMBeans();
ReportScheduler scheduler = new ReportScheduler(metricRegistry);
scheduler.start(1, TimeUnit.SECONDS);
counter.inc();
TimerContext timerContext = timer.start();
Thread.sleep(100);
timerContext.stop();
Thread.sleep(950);
counter.inc(2);
Thread.sleep(1050);
scheduler.stop();
// 校验MBean中的值
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
System.out.println("TotalCount from MBean:" + mBeanServer.getAttribute(new ObjectName("metrics-example", "name", "UserService.getUser.counter"), "TotalCount").toString());
}
Aggregations