|
15 | 15 | */
|
16 | 16 | package com.arpnetworking.tsdcore.sinks;
|
17 | 17 |
|
18 |
| -import akka.actor.AbstractActor; |
| 18 | +import akka.actor.AbstractActorWithTimers; |
19 | 19 | import akka.actor.Props;
|
20 | 20 | import akka.actor.Status;
|
21 | 21 | import akka.pattern.Patterns;
|
|
51 | 51 | *
|
52 | 52 | * @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
|
53 | 53 | */
|
54 |
| -public class HttpSinkActor extends AbstractActor { |
| 54 | +public class HttpSinkActor extends AbstractActorWithTimers { |
55 | 55 | /**
|
56 | 56 | * Factory method to create a Props.
|
57 | 57 | *
|
@@ -120,6 +120,7 @@ public HttpSinkActor(
|
120 | 120 | _httpSinkAttemptsName = "sinks/http_post/" + _sink.getMetricSafeName() + "/attempts";
|
121 | 121 | _samplesSentName = "sinks/http_post/" + sink.getMetricSafeName() + "/samples_sent";
|
122 | 122 | _samplesDroppedName = "sinks/http_post/" + _sink.getMetricSafeName() + "/samples_dropped";
|
| 123 | + timers().startTimerAtFixedRate("metrics", SampleMetrics.INSTANCE, Duration.ofSeconds(1), Duration.ofSeconds(1)); |
123 | 124 | }
|
124 | 125 |
|
125 | 126 | @Override
|
@@ -244,6 +245,10 @@ public Receive createReceive() {
|
244 | 245 | .setThrowable(message.cause())
|
245 | 246 | .log();
|
246 | 247 | })
|
| 248 | + .match(SampleMetrics.class, message -> { |
| 249 | + _periodicMetrics.recordCounter(_pendingRequestsQueueSizeName, _pendingRequests.size()); |
| 250 | + _periodicMetrics.recordCounter(_inflightRequestsCountName, _inflightRequestsCount); |
| 251 | + }) |
247 | 252 | .matchAny(message -> {
|
248 | 253 | LOGGER.error()
|
249 | 254 | .setMessage("Unexpected message")
|
@@ -654,4 +659,8 @@ public void onThrowable(final Throwable throwable) {
|
654 | 659 |
|
655 | 660 | private final CompletableFuture<Response> _promise;
|
656 | 661 | }
|
| 662 | + private static final class SampleMetrics { |
| 663 | + private SampleMetrics() { } |
| 664 | + private static final SampleMetrics INSTANCE = new SampleMetrics(); |
| 665 | + } |
657 | 666 | }
|
0 commit comments