use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class ReportScheduler method report.
/**
* 定期计算所有Metrics, 并调用所有Reporter进行汇报.
*/
public void report() {
// 取出所有Metrics, 未按名称排序.
Map<String, Gauge> gaugeMap = metricRegistry.getGauges();
Map<String, Counter> counterMap = metricRegistry.getCounters();
Map<String, Histogram> histogramMap = metricRegistry.getHistograms();
Map<String, Timer> timerMap = metricRegistry.getTimers();
// 计算单位时间内的metrics值, 存入该Metrics的Snapshot中,并清零原始数据
for (Gauge gauge : gaugeMap.values()) {
gauge.calculateMetric();
}
for (Counter counter : counterMap.values()) {
counter.calculateMetric();
}
for (Histogram histogram : histogramMap.values()) {
histogram.calculateMetric();
}
for (Timer timer : timerMap.values()) {
timer.calculateMetric();
}
// 调度所有Reporters 输出 metrics值
for (Reporter reporter : reporters) {
reporter.report(gaugeMap, counterMap, histogramMap, timerMap);
}
}
use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class HistogramTest method emptyMesures.
@Test
public void emptyMesures() {
Histogram histogram = new Histogram(90d, 95d);
HistogramMetric metric = histogram.calculateMetric();
assertThat(metric.min).isZero();
assertThat(metric.max).isZero();
assertThat(metric.avg).isZero();
assertThat(metric.pcts.get(90d)).isZero();
}
use of org.springside.modules.metrics.metric.Histogram 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();
}
use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class HistogramTest method fewData.
@Test
public void fewData() {
Histogram histogram = new Histogram(90d, 95d);
histogram.update(1);
HistogramMetric metric = histogram.calculateMetric();
assertThat(metric.pcts.get(90d)).isEqualTo(1);
assertThat(metric.pcts.get(95d)).isEqualTo(1);
for (int i = 1; i <= 3; i++) {
histogram.update(i);
}
metric = histogram.calculateMetric();
assertThat(metric.min).isEqualTo(1);
assertThat(metric.max).isEqualTo(3);
assertThat(metric.avg).isEqualTo(2);
assertThat(metric.pcts.get(90d)).isEqualTo(3);
assertThat(metric.pcts.get(95d)).isEqualTo(3);
}
use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class HistogramTest method normal.
@Test
public void normal() {
Histogram histogram = new Histogram(90d, 95d);
for (int i = 1; i <= 100; i++) {
histogram.update(i);
}
HistogramMetric metric = histogram.calculateMetric();
assertThat(metric.min).isEqualTo(1);
assertThat(metric.max).isEqualTo(100);
assertThat(metric.avg).isEqualTo(50.5);
assertThat(metric.pcts.get(90d)).isEqualTo(90);
assertThat(metric.pcts.get(95d)).isEqualTo(95);
for (int i = 1; i <= 100; i++) {
histogram.update(i * 2);
}
metric = histogram.calculateMetric();
assertThat(metric.min).isEqualTo(2);
assertThat(metric.max).isEqualTo(200);
assertThat(metric.avg).isEqualTo(101);
assertThat(metric.pcts.get(90d)).isEqualTo(180);
assertThat(metric.pcts.get(95d)).isEqualTo(190);
}
Aggregations