Search in sources :

Example 6 with Histogram

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

Example 7 with Histogram

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

Example 8 with Histogram

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

Example 9 with Histogram

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

Aggregations

Histogram (org.springside.modules.metrics.metric.Histogram)9 Test (org.junit.Test)7 HistogramMetric (org.springside.modules.metrics.metric.HistogramMetric)5 Counter (org.springside.modules.metrics.metric.Counter)2 Timer (org.springside.modules.metrics.metric.Timer)2 Gauge (org.springside.modules.metrics.metric.Gauge)1 TimerContext (org.springside.modules.metrics.metric.Timer.TimerContext)1 Slf4jReporter (org.springside.modules.metrics.reporter.Slf4jReporter)1 MockClock (org.springside.modules.metrics.utils.Clock.MockClock)1