Search in sources :

Example 6 with Timer

use of org.springside.modules.metrics.metric.Timer in project springside4 by springside.

the class ReporterTest method runReport.

private void runReport(Reporter reporter) {
    MetricRegistry metricRegistry = new MetricRegistry();
    MockClock clock = new MockClock();
    Counter.clock = clock;
    Timer.clock = clock;
    // counter
    Counter counter = metricRegistry.counter(MetricRegistry.name("UserService", "getUser.counter"));
    counter.inc(4);
    Counter counter2 = metricRegistry.counter(MetricRegistry.name("UserService", "setUser.counter"));
    counter2.inc(6);
    clock.increaseTime(1000);
    // histogram
    Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency"));
    for (int i = 1; i <= 100; i++) {
        histogram.update(i);
    }
    Histogram histogram2 = metricRegistry.histogram(MetricRegistry.name("UserService", "setUser.latency"));
    for (int i = 1; i <= 100; i++) {
        histogram2.update(i * 2);
    }
    // timer
    Timer timer = metricRegistry.timer(MetricRegistry.name("UserService", "getUser.timer"));
    for (int i = 1; i <= 10; i++) {
        TimerContext timerContext = timer.start();
        clock.increaseTime(25);
        timerContext.stop();
    }
    Timer timer2 = metricRegistry.timer(MetricRegistry.name("UserService", "setUser.timer"));
    for (int i = 1; i <= 10; i++) {
        TimerContext timerContext = timer2.start();
        clock.increaseTime(75);
        timerContext.stop();
    }
    // totally 2 seconds past
    ReportScheduler scheduler = new ReportScheduler(metricRegistry, reporter);
    scheduler.report();
}
Also used : Histogram(org.springside.modules.metrics.metric.Histogram) Counter(org.springside.modules.metrics.metric.Counter) Timer(org.springside.modules.metrics.metric.Timer) TimerContext(org.springside.modules.metrics.metric.Timer.TimerContext) MockClock(org.springside.modules.metrics.utils.Clock.MockClock)

Aggregations

Timer (org.springside.modules.metrics.metric.Timer)6 Test (org.junit.Test)4 TimerContext (org.springside.modules.metrics.metric.Timer.TimerContext)4 Counter (org.springside.modules.metrics.metric.Counter)3 Histogram (org.springside.modules.metrics.metric.Histogram)2 MockClock (org.springside.modules.metrics.utils.Clock.MockClock)2 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 JmxExporter (org.springside.modules.metrics.exporter.JmxExporter)1 Gauge (org.springside.modules.metrics.metric.Gauge)1 TimerMetric (org.springside.modules.metrics.metric.TimerMetric)1 Slf4jReporter (org.springside.modules.metrics.reporter.Slf4jReporter)1