-
Notifications
You must be signed in to change notification settings - Fork 986
Command Latency Metrics
Command latency metrics give insight about command execution and latencies. Metrics are collected for every completed command and are enabled by default.
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 rx-java 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 |
|
|
An |
||
Reset latencies after publish |
|
|
Allows to control 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. |
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