Search in sources :

Example 1 with Monitor

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

the class MetricTypeTest method givenStatsTimer_whenExecuteTask_thenStatsCalculated.

@Test
public // ==
void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Exception {
    System.setProperty("netflix.servo", "1000");
    StatsTimer timer = new StatsTimer(MonitorConfig.builder("test").build(), new StatsConfig.Builder().withComputeFrequencyMillis(2000).withPercentiles(new double[] { 99.0, 95.0, 90.0 }).withPublishMax(true).withPublishMin(true).withPublishCount(true).withPublishMean(true).withPublishStdDev(true).withPublishVariance(true).build(), MILLISECONDS);
    Stopwatch stopwatch = timer.start();
    MILLISECONDS.sleep(1);
    timer.record(3, MILLISECONDS);
    stopwatch.stop();
    stopwatch = timer.start();
    timer.record(6, MILLISECONDS);
    MILLISECONDS.sleep(2);
    stopwatch.stop();
    assertEquals("timer should count 12 milliseconds in total", 12, timer.getTotalTime());
    assertEquals("timer should count 12 milliseconds in total", 12, timer.getTotalMeasurement());
    assertEquals("timer should record 4 updates", 4, timer.getCount());
    assertEquals("stats timer value time-cost/update should be 2", 3, timer.getValue().intValue());
    final Map<String, Number> metricMap = timer.getMonitors().stream().collect(toMap(monitor -> getMonitorTagValue(monitor, "statistic"), monitor -> (Number) monitor.getValue()));
    assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90"));
}
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) StatsTimer(com.netflix.servo.monitor.StatsTimer) Stopwatch(com.netflix.servo.monitor.Stopwatch) Test(org.junit.Test)

Example 2 with Monitor

use of com.netflix.servo.monitor.Monitor in project Hystrix by Netflix.

the class HystrixServoMetricsPublisherCollapser method initialize.

@Override
public void initialize() {
    /* list of monitors */
    List<Monitor<?>> monitors = getServoMonitors();
    // publish metrics together under a single composite (it seems this name is ignored)
    MonitorConfig commandMetricsConfig = MonitorConfig.builder("HystrixCollapser_" + key.name()).build();
    BasicCompositeMonitor commandMetricsMonitor = new BasicCompositeMonitor(commandMetricsConfig, monitors);
    DefaultMonitorRegistry.getInstance().register(commandMetricsMonitor);
    RollingCollapserBatchSizeDistributionStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    RollingCollapserEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    CumulativeCollapserEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
}
Also used : Monitor(com.netflix.servo.monitor.Monitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) MonitorConfig(com.netflix.servo.monitor.MonitorConfig)

Example 3 with Monitor

use of com.netflix.servo.monitor.Monitor in project Hystrix by Netflix.

the class HystrixServoMetricsPublisherThreadPool method initialize.

@Override
public void initialize() {
    /* list of monitors */
    List<Monitor<?>> monitors = getServoMonitors();
    // publish metrics together under a single composite (it seems this name is ignored)
    MonitorConfig commandMetricsConfig = MonitorConfig.builder("HystrixThreadPool_" + key.name()).build();
    BasicCompositeMonitor commandMetricsMonitor = new BasicCompositeMonitor(commandMetricsConfig, monitors);
    DefaultMonitorRegistry.getInstance().register(commandMetricsMonitor);
    RollingThreadPoolEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    CumulativeThreadPoolEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    RollingThreadPoolMaxConcurrencyStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
}
Also used : Monitor(com.netflix.servo.monitor.Monitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) MonitorConfig(com.netflix.servo.monitor.MonitorConfig)

Example 4 with Monitor

use of com.netflix.servo.monitor.Monitor in project Hystrix by Netflix.

the class HystrixServoMetricsPublisherCommand method initialize.

@Override
public void initialize() {
    /* list of monitors */
    List<Monitor<?>> monitors = getServoMonitors();
    // publish metrics together under a single composite (it seems this name is ignored)
    MonitorConfig commandMetricsConfig = MonitorConfig.builder("HystrixCommand_" + key.name()).build();
    BasicCompositeMonitor commandMetricsMonitor = new BasicCompositeMonitor(commandMetricsConfig, monitors);
    DefaultMonitorRegistry.getInstance().register(commandMetricsMonitor);
    RollingCommandEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    CumulativeCommandEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    RollingCommandLatencyDistributionStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    RollingCommandUserLatencyDistributionStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
    RollingCommandMaxConcurrencyStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
}
Also used : Monitor(com.netflix.servo.monitor.Monitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) BasicCompositeMonitor(com.netflix.servo.monitor.BasicCompositeMonitor) MonitorConfig(com.netflix.servo.monitor.MonitorConfig)

Example 5 with Monitor

use of com.netflix.servo.monitor.Monitor 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

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