Report Lettuce command latency via Micrometer.

This commit is contained in:
Jon Chambers
2020-10-20 11:51:18 -04:00
committed by Jon Chambers
parent 45687513bf
commit 236cef4b56
2 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
package org.whispersystems.textsecuregcm.metrics;
import io.lettuce.core.metrics.CommandLatencyRecorder;
import io.lettuce.core.protocol.ProtocolKeyword;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static com.codahale.metrics.MetricRegistry.name;
public class MicrometerLettuceCommandLatencyRecorder implements CommandLatencyRecorder {
private static final String FIRST_RESPONSE_TIMER_NAME = name(MicrometerLettuceCommandLatencyRecorder.class, "firstResponse");
private static final String COMPLETION_TIMER_NAME = name(MicrometerLettuceCommandLatencyRecorder.class, "completion");
@Override
public void recordCommandLatency(final SocketAddress local, final SocketAddress remote, final ProtocolKeyword commandType, final long firstResponseLatency, final long completionLatency) {
final List<Tag> tags = List.of(Tag.of("redisHost", remote.toString()), Tag.of("command", commandType.name()));
Metrics.timer(FIRST_RESPONSE_TIMER_NAME, tags).record(firstResponseLatency, TimeUnit.NANOSECONDS);
Metrics.timer(COMPLETION_TIMER_NAME, tags).record(completionLatency, TimeUnit.NANOSECONDS);
}
}