use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class HistogramTest method emptyPcts.
@Test()
public void emptyPcts() {
Histogram histogram = new Histogram();
for (int i = 1; i <= 3; i++) {
histogram.update(i);
}
HistogramMetric metric = histogram.calculateMetric();
assertThat(metric.max).isEqualTo(3);
assertThat(metric.pcts).isEmpty();
assertThat(metric.pcts.get(90d)).isNull();
}
use of org.springside.modules.metrics.metric.Histogram 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();
}
use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class MetricRegistryTest method defaultPcts.
@Test
public void defaultPcts() {
MetricRegistry metricRegistry = new MetricRegistry();
// set pcts 60,70
Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.histogram.setPcts"), 60d, 70d);
for (int i = 1; i <= 100; i++) {
histogram.update(i);
}
HistogramMetric metric = histogram.calculateMetric();
assertThat(metric.pcts.get(60d)).isEqualTo(60);
assertThat(metric.pcts.get(70d)).isEqualTo(70);
// new default 50
metricRegistry.setDefaultPcts(new Double[] { 50d });
Histogram histogramWithNewDefaultPcts = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.histogram.newDefault"));
for (int i = 1; i <= 100; i++) {
histogramWithNewDefaultPcts.update(i);
}
metric = histogramWithNewDefaultPcts.calculateMetric();
assertThat(metric.pcts.get(50d)).isEqualTo(50);
assertThat(metric.pcts.get(90d)).isNull();
}
use of org.springside.modules.metrics.metric.Histogram in project springside4 by springside.
the class MetricRegistryTest method histogram.
@Test
public void histogram() {
MetricRegistry metricRegistry = new MetricRegistry();
Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency"));
assertThat(histogram).isNotNull();
Map<String, Histogram> histograms = metricRegistry.getHistograms();
Histogram histogram2 = histograms.get("UserService.getUser.latency");
assertThat(histogram2).isNotNull().isSameAs(histogram);
Histogram histogram3 = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency"));
assertThat(histogram3).isNotNull().isSameAs(histogram);
}
Aggregations