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"));
}
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();
}
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();
}
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();
}
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)));
}
Aggregations