use of org.springside.modules.metrics.reporter.Slf4jReporter in project springside4 by springside.
the class MetricExamples method timerExample.
@Test
public void timerExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用slf4j reporter,并使用自定义logger名字
Slf4jReporter slf4jReporter = new Slf4jReporter("mymetrics");
ReportScheduler scheduler = new ReportScheduler(metricRegistry);
scheduler.addReporter(slf4jReporter);
scheduler.start(1, TimeUnit.SECONDS);
Timer timer = metricRegistry.timer(MetricRegistry.name("UserService", "getUser.timer"), new Double[] { 99d, 99.99d });
// 写法1
TimerContext timerContext = timer.start();
Thread.sleep(100);
timerContext.stop();
timerContext = timer.start();
Thread.sleep(200);
timerContext.stop();
Thread.sleep(750);
// 用法2
long start = System.currentTimeMillis();
Thread.sleep(150);
timer.update(start);
start = System.currentTimeMillis();
Thread.sleep(250);
timer.update(start);
Thread.sleep(650);
scheduler.stop();
}
use of org.springside.modules.metrics.reporter.Slf4jReporter in project springside4 by springside.
the class MetricExamples method histogramExample.
@Test
public void histogramExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用slf4j reporter,并使用默认logger名字
Slf4jReporter slf4jReporter = new Slf4jReporter();
ReportScheduler scheduler = new ReportScheduler(metricRegistry, slf4jReporter);
scheduler.start(1, TimeUnit.SECONDS);
Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency"));
histogram.update(1);
histogram.update(100);
Thread.sleep(1050);
// 增加百分位
histogram.setPcts(new Double[] { 99d, 99.95d });
histogram.update(2);
histogram.update(200);
Thread.sleep(1050);
scheduler.stop();
}
Aggregations