-
Notifications
You must be signed in to change notification settings - Fork 985
Command Latency Metrics
Command latency metrics give insight into command execution and latencies. Metrics are collected for every completed command. Lettuce has two mechanisms to collect latency metrics:
-
Built-in (since version 3.4 using HdrHistogram and LatencyUtils. Enabled by default if both libraries are available on the classpath.)
-
Micrometer (since version 6.1)
Each command is tracked with:
-
Execution count
-
Latency to first response (min, max, percentiles)
-
Latency to complete (min, max, percentiles)
Command latencies are tracked on remote endpoint (distinction by host and port or socket path) and command type level (GET
, SET
, …). It is possible to track command latencies on a per-connection level (see DefaultCommandLatencyCollectorOptions
).
Command latencies are transported using Events on the EventBus
. The EventBus
can be obtained from
the client resources of the client instance. Please keep in mind that the EventBus
is used for various
event types. Filter on the event type if you’re interested only in particular event types.
RedisClient client = RedisClient.create();
EventBus eventBus = client.getResources().eventBus();
Subscription subscription = eventBus.get()
.filter(redisEvent -> redisEvent instanceof CommandLatencyEvent)
.cast(CommandLatencyEvent.class)
.subscribe(e -> System.out.println(e.getLatencies()));
The EventBus
uses Reactor Processors to publish events. This example prints the received latencies to stdout
. The interval and the collection of command latency metrics can be configured in the ClientResources
.
Lettuce requires the LatencyUtils dependency (at least 2.0) to provide latency metrics. Make sure to include that dependency on your classpath. Otherwise, you won’t be able using latency metrics.
If using Maven, add the following dependency to your pom.xml:
<dependency>
<groupId>org.latencyutils</groupId>
<artifactId>LatencyUtils</artifactId>
<version>2.0.3</version>
</dependency>
To disable metrics collection, use own ClientResources
with a disabled DefaultCommandLatencyCollectorOptions
:
ClientResources res = DefaultClientResources
.builder()
.commandLatencyCollectorOptions( DefaultCommandLatencyCollectorOptions.disabled())
.build();
RedisClient client = RedisClient.create(res);
The following settings are available to configure from DefaultCommandLatencyCollectorOptions
:
Name | Method | Default |
---|---|---|
Disable metrics tracking |
|
|
Disables tracking of command latency metrics. |
||
Latency time unit |
|
|
The target unit for command latency values. All values in the |
||
Latency percentiles |
|
|
A |
||
Reset latencies after publish |
|
|
Allows controlling whether the latency metrics are reset to zero one they were published. Setting |
||
Local socket distinction |
|
|
Enables per connection metrics tracking instead of per host/port. If |
The following settings are available to configure from DefaultEventPublisherOptions
:
Name | Method | Default |
---|---|---|
Disable event publisher |
|
|
Disables event publishing. |
||
Event publishing time unit |
|
|
The |
||
Event publishing interval |
|
|
The interval for the event publishing. |
Commands are tracked by using two Micrometer Timer
s: lettuce.command.firstresponse
and lettuce.command.completion
. The following tags are attached to each timer:
-
command
: Name of the command (GET
,SET
, …) -
local
: Local socket (localhost/127.0.0.1:45243
orANY
when local distinction is disabled, which is the default behavior) -
remote
: Remote socket (localhost/127.0.0.1:6379
)
Command latencies are reported using the provided MeterRegistry
.
MeterRegistry meterRegistry = …;
MicrometerOptions options = MicrometerOptions.create();
ClientResources resources = ClientResources.builder().commandLatencyRecorder(new MicrometerCommandLatencyRecorder(meterRegistry, options)).build();
RedisClient client = RedisClient.create(resources);
Lettuce requires Micrometer (micrometer-core
) to integrate with Micrometer.
If using Maven, add the following dependency to your pom.xml:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version> <!-- e.g. micrometer.version==1.6.0 -->
</dependency>
The following settings are available to configure from MicrometerOptions
:
Name | Method | Default |
---|---|---|
Disable metrics tracking |
|
|
Disables tracking of command latency metrics. |
||
Histogram |
|
|
Enable histogram buckets used to generate aggregable percentile approximations in monitoring systems that have query facilities to do so. |
||
Local socket distinction |
|
|
Enables per connection metrics tracking instead of per host/port. If |
||
Maximum Latency |
|
|
Sets the maximum value that this timer is expected to observe. Applies only if Histogram publishing is enabled. |
||
Minimum Latency |
|
|
Sets the minimum value that this timer is expected to observe. Applies only if Histogram publishing is enabled. |
||
Additional Tags |
|
|
Extra tags to add to the generated metrics. |
||
Latency percentiles |
|
|
A |
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals