use of org.springside.modules.metrics.reporter.ConsoleReporter in project springside4 by springside.
the class MetricExamples method counterExample.
@Test
public void counterExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用ConsoleReporter
ConsoleReporter consoleReporter = new ConsoleReporter();
Counter counter = metricRegistry.counter(MetricRegistry.name("UserService", "getUser.counter"));
ReportScheduler scheduler = new ReportScheduler(metricRegistry, consoleReporter);
scheduler.start(1, TimeUnit.SECONDS);
counter.inc();
Thread.sleep(1050);
counter.inc(2);
Thread.sleep(1050);
scheduler.stop();
}
use of org.springside.modules.metrics.reporter.ConsoleReporter in project springside4 by springside.
the class ReporterTest method schedulerStartStop.
@Test
public void schedulerStartStop() throws InterruptedException {
ReportScheduler scheduler = new ReportScheduler(new MetricRegistry(), new ConsoleReporter());
scheduler.start(1, TimeUnit.SECONDS);
Thread.sleep(2000);
scheduler.stop();
}
use of org.springside.modules.metrics.reporter.ConsoleReporter in project springside4 by springside.
the class MetricExamples method gaugeExample.
@Test
public void gaugeExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用ConsoleReporter
ConsoleReporter consoleReporter = new ConsoleReporter();
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
Gauge<Long> usedMemoryGague = new Gauge<Long>() {
public Long getValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
Gauge<Long> cachedUsedMemoryGague = new CachedGauge<Long>(10, TimeUnit.SECONDS) {
public Long loadValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
metricRegistry.registerGauge(MetricRegistry.name("JVM", "usedMemory"), usedMemoryGague);
metricRegistry.registerGauge(MetricRegistry.name("JVM", "cachedUsedMemory"), cachedUsedMemoryGague);
ReportScheduler scheduler = new ReportScheduler(metricRegistry, consoleReporter);
scheduler.start(1, TimeUnit.SECONDS);
Thread.sleep(1050);
// use some memory
List<Integer> list = new ArrayList<Integer>(200000);
list.add(1);
Thread.sleep(1050);
scheduler.stop();
}
Aggregations