From 79abf25feebd5b65b8a5acc51a9c5a35310d918a Mon Sep 17 00:00:00 2001 From: Philip Clarke Date: Wed, 20 Sep 2017 10:37:13 +0100 Subject: [PATCH 1/2] Use SlidingTimeWindowArrayReservoir for timers with a default configurable interval of 10 seconds --- .../micro/server/event/metrics/Configuration.java | 3 +++ .../micro/server/event/metrics/MetricsCatcher.java | 13 +++++++++---- .../event/metrics/MetricsCatcherConfigOffTest.java | 2 +- .../server/event/metrics/MetricsCatcherTest.java | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java b/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java index 0d88df66d..581300776 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java +++ b/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java @@ -24,6 +24,7 @@ class Configuration { private final int numJobs; private final int holdJobsForMinutes; + private final int timerIntervalSeconds; private final String prefix; @Autowired @@ -35,6 +36,7 @@ public Configuration(@Value("${event.metrics.capture.errors.by.type:true}") bool @Value("${event.metrics.capture.queries.minutes:180}") int holdQueriesForMinutes, @Value("${event.metrics.capture.number.of.jobs:10000}") int numJobs, @Value("${event.metrics.capture.jobs.minutes:180}") int holdJobsForMinutes, + @Value("${event.metrics.capture.timer.interval.seconds:10}") int timerIntervalSeconds, @Value("${event.metrics.capture.jobs.prefix:#{null}}") String prefix) { super(); this.errorsByType = errorsByType; @@ -45,6 +47,7 @@ public Configuration(@Value("${event.metrics.capture.errors.by.type:true}") bool this.holdQueriesForMinutes = holdQueriesForMinutes; this.numJobs = numJobs; this.holdJobsForMinutes = holdJobsForMinutes; + this.timerIntervalSeconds = timerIntervalSeconds; this.prefix = Optional.ofNullable(prefix) .orElseGet(() -> MetricsCatcher.class.getTypeName()); } diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java b/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java index 3f40357aa..bcc5429ce 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java +++ b/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java @@ -2,6 +2,8 @@ import com.aol.micro.server.events.GenericEvent; import com.aol.micro.server.spring.metrics.InstantGauge; +import com.codahale.metrics.SlidingTimeWindowArrayReservoir; +import com.codahale.metrics.Timer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -20,6 +22,7 @@ import com.google.common.eventbus.Subscribe; import java.util.Objects; +import java.util.concurrent.TimeUnit; @Component public class MetricsCatcher { @@ -59,8 +62,7 @@ public void requestStart(AddQuery data) { registry.meter(queryStartName(rd) + "-meter") .mark(); - queries.start(rd.getCorrelationId(), registry.timer(queryEndName(rd) + "-timer") - .time()); + queries.start(rd.getCorrelationId(), timer(queryEndName(rd) + "-timer").time()); registry.counter(prefix + ".requests-active-" + rd.getType() + "-count") .inc(); ((InstantGauge) registry.gauge(prefix + ".requests-started-" + rd.getType() + "-interval-count", @@ -135,8 +137,7 @@ public void jobStarted(JobStartEvent data) { registry.meter(prefix + ".job-meter-" + data.getType()) .mark(); - jobs.start(data.getCorrelationId(), registry.timer(prefix + ".job-timer-" + data.getType()) - .time()); + jobs.start(data.getCorrelationId(), timer(prefix + ".job-timer-" + data.getType()).time()); registry.counter(prefix + ".jobs-active-" + data.getType() + "-count") .inc(); } @@ -223,4 +224,8 @@ public void genericEvent(GenericEvent event) { private String name(ErrorCode c) { return prefix + ".error-" + c.getSeverity() + "-" + c.getErrorId(); } + + private Timer timer (String name) { + return registry.timer(name, () -> new Timer(new SlidingTimeWindowArrayReservoir(configuration.getTimerIntervalSeconds(), TimeUnit.SECONDS))); + } } diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java index 04bf7dd01..c5d0832c1 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java +++ b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java @@ -27,7 +27,7 @@ public void setup() { registry = new MetricRegistry(); bus = new EventBus(); config = new Configuration( - false, false, false, false, 5, 6, 7, 8, "bob"); + false, false, false, false, 5, 6, 7, 8, 10, "bob"); catcher = new MetricsCatcher<>( registry, bus, config); } diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java index 6eb51d09a..dc8ce6d19 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java +++ b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java @@ -29,7 +29,7 @@ public void setup() { registry = new MetricRegistry(); bus = new EventBus(); config = new Configuration( - true, true, true, true, 5, 6, 7, 8, "bob"); + true, true, true, true, 5, 6, 7, 8, 10,"bob"); catcher = new MetricsCatcher<>( registry, bus, config); } From 40ea257d729566338cbaf8b8ca34580dfcd77c32 Mon Sep 17 00:00:00 2001 From: Philip Clarke Date: Wed, 20 Sep 2017 10:50:44 +0100 Subject: [PATCH 2/2] update readme for new counters and properties --- micro-event-metrics/readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/micro-event-metrics/readme.md b/micro-event-metrics/readme.md index c25d9a5f0..41b53693c 100644 --- a/micro-event-metrics/readme.md +++ b/micro-event-metrics/readme.md @@ -108,9 +108,14 @@ Number of active jobs to cache in memory ```text com.aol.micro.server.event.metrics.MetricsCatcher.requests-started +com.aol.micro.server.event.metrics.MetricsCatcher.requests-started-interval-count com.aol.micro.server.event.metrics.MetricsCatcher.request-start- +com.aol.micro.server.event.metrics.MetricsCatcher.request-start--interval-count com.aol.micro.server.event.metrics.MetricsCatcher.requests-completed +com.aol.micro.server.event.metrics.MetricsCatcher.requests-completed-interval-type com.aol.micro.server.event.metrics.MetricsCatcher.request-completed- +com.aol.micro.server.event.metrics.MetricsCatcher.request-completed--interval-count + ``` #### Timers : @@ -172,6 +177,8 @@ event.metrics.capture.jobs.by.type=true # jobsByType, event.metrics.capture.number.of.queries=10000 # numQueries, event.metrics.capture.queries.minutes=180 # holdQueriesForMinutes, event.metrics.capture.number.of.jobs=10000 # numJobs, -event.metrics.capture.jobs.minutes=180 +event.metrics.capture.jobs.minutes=180, +event.metrics.capture.timer.interval.seconds=10 +event.metrics.capture.jobs.prefix=null ```