Skip to content

Commit 2106b9e

Browse files
committed
periodically sample http sinks for metrics about queue size and inflight
1 parent af1c569 commit 2106b9e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/com/arpnetworking/tsdcore/sinks/HttpSinkActor.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.arpnetworking.tsdcore.sinks;
1717

18-
import akka.actor.AbstractActor;
18+
import akka.actor.AbstractActorWithTimers;
1919
import akka.actor.Props;
2020
import akka.actor.Status;
2121
import akka.pattern.Patterns;
@@ -51,7 +51,7 @@
5151
*
5252
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
5353
*/
54-
public class HttpSinkActor extends AbstractActor {
54+
public class HttpSinkActor extends AbstractActorWithTimers {
5555
/**
5656
* Factory method to create a Props.
5757
*
@@ -120,6 +120,7 @@ public HttpSinkActor(
120120
_httpSinkAttemptsName = "sinks/http_post/" + _sink.getMetricSafeName() + "/attempts";
121121
_samplesSentName = "sinks/http_post/" + sink.getMetricSafeName() + "/samples_sent";
122122
_samplesDroppedName = "sinks/http_post/" + _sink.getMetricSafeName() + "/samples_dropped";
123+
timers().startTimerAtFixedRate("metrics", SampleMetrics.INSTANCE, Duration.ofSeconds(1), Duration.ofSeconds(1));
123124
}
124125

125126
@Override
@@ -244,6 +245,10 @@ public Receive createReceive() {
244245
.setThrowable(message.cause())
245246
.log();
246247
})
248+
.match(SampleMetrics.class, message -> {
249+
_periodicMetrics.recordCounter(_pendingRequestsQueueSizeName, _pendingRequests.size());
250+
_periodicMetrics.recordCounter(_inflightRequestsCountName, _inflightRequestsCount);
251+
})
247252
.matchAny(message -> {
248253
LOGGER.error()
249254
.setMessage("Unexpected message")
@@ -654,4 +659,8 @@ public void onThrowable(final Throwable throwable) {
654659

655660
private final CompletableFuture<Response> _promise;
656661
}
662+
private static final class SampleMetrics {
663+
private SampleMetrics() { }
664+
private static final SampleMetrics INSTANCE = new SampleMetrics();
665+
}
657666
}

0 commit comments

Comments
 (0)