Search in sources :

Example 1 with ConsoleReporter

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();
}
Also used : Counter(org.springside.modules.metrics.metric.Counter) ConsoleReporter(org.springside.modules.metrics.reporter.ConsoleReporter) Test(org.junit.Test)

Example 2 with ConsoleReporter

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();
}
Also used : ConsoleReporter(org.springside.modules.metrics.reporter.ConsoleReporter) Test(org.junit.Test)

Example 3 with ConsoleReporter

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();
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) ConsoleReporter(org.springside.modules.metrics.reporter.ConsoleReporter) CachedGauge(org.springside.modules.metrics.metric.CachedGauge) ArrayList(java.util.ArrayList) Gauge(org.springside.modules.metrics.metric.Gauge) CachedGauge(org.springside.modules.metrics.metric.CachedGauge) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ConsoleReporter (org.springside.modules.metrics.reporter.ConsoleReporter)3 MemoryMXBean (java.lang.management.MemoryMXBean)1 ArrayList (java.util.ArrayList)1 CachedGauge (org.springside.modules.metrics.metric.CachedGauge)1 Counter (org.springside.modules.metrics.metric.Counter)1 Gauge (org.springside.modules.metrics.metric.Gauge)1