Search in sources :

Example 1 with BucketTimer

use of com.netflix.servo.monitor.BucketTimer in project tutorials by eugenp.

the class MetricTypeTest method givenBucketTimer_whenRecord_thenStatsCalculated.

@Test
public void givenBucketTimer_whenRecord_thenStatsCalculated() throws Exception {
    BucketTimer timer = new BucketTimer(MonitorConfig.builder("test").build(), new BucketConfig.Builder().withBuckets(new long[] { 2L, 5L }).withTimeUnit(SECONDS).build(), SECONDS);
    timer.record(3);
    timer.record(6);
    assertEquals("timer should count 9 seconds in total", 9, timer.getTotalTime().intValue());
    final Map<String, Long> metricMap = timer.getMonitors().stream().filter(monitor -> monitor.getConfig().getTags().containsKey("servo.bucket")).collect(toMap(monior -> getMonitorTagValue(monior, "servo.bucket"), monitor -> (Long) monitor.getValue()));
    assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L)));
}
Also used : Counter(com.netflix.servo.monitor.Counter) BucketTimer(com.netflix.servo.monitor.BucketTimer) StepCounter(com.netflix.servo.monitor.StepCounter) Monitor(com.netflix.servo.monitor.Monitor) Assert.assertThat(org.junit.Assert.assertThat) Collectors.toMap(java.util.stream.Collectors.toMap) StatsConfig(com.netflix.servo.stats.StatsConfig) BasicTimer(com.netflix.servo.monitor.BasicTimer) StatsTimer(com.netflix.servo.monitor.StatsTimer) Map(java.util.Map) BasicGauge(com.netflix.servo.monitor.BasicGauge) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Gauge(com.netflix.servo.monitor.Gauge) MaxGauge(com.netflix.servo.monitor.MaxGauge) Matchers.allOf(org.hamcrest.Matchers.allOf) BasicCounter(com.netflix.servo.monitor.BasicCounter) Test(org.junit.Test) PeakRateCounter(com.netflix.servo.monitor.PeakRateCounter) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Ignore(org.junit.Ignore) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) MonitorConfig(com.netflix.servo.monitor.MonitorConfig) Stopwatch(com.netflix.servo.monitor.Stopwatch) Monitors(com.netflix.servo.monitor.Monitors) BasicInformational(com.netflix.servo.monitor.BasicInformational) BucketConfig(com.netflix.servo.monitor.BucketConfig) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) BucketTimer(com.netflix.servo.monitor.BucketTimer) Test(org.junit.Test)

Aggregations

BasicCounter (com.netflix.servo.monitor.BasicCounter)1 BasicGauge (com.netflix.servo.monitor.BasicGauge)1 BasicInformational (com.netflix.servo.monitor.BasicInformational)1 BasicTimer (com.netflix.servo.monitor.BasicTimer)1 BucketConfig (com.netflix.servo.monitor.BucketConfig)1 BucketTimer (com.netflix.servo.monitor.BucketTimer)1 Counter (com.netflix.servo.monitor.Counter)1 Gauge (com.netflix.servo.monitor.Gauge)1 MaxGauge (com.netflix.servo.monitor.MaxGauge)1 Monitor (com.netflix.servo.monitor.Monitor)1 MonitorConfig (com.netflix.servo.monitor.MonitorConfig)1 Monitors (com.netflix.servo.monitor.Monitors)1 PeakRateCounter (com.netflix.servo.monitor.PeakRateCounter)1 StatsTimer (com.netflix.servo.monitor.StatsTimer)1 StepCounter (com.netflix.servo.monitor.StepCounter)1 Stopwatch (com.netflix.servo.monitor.Stopwatch)1 StatsConfig (com.netflix.servo.stats.StatsConfig)1 Map (java.util.Map)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1