Class LatencyGauge


@Deprecated public class LatencyGauge extends Gauge<Long>
Deprecated.
Use Timer for latency measurements
A metric which measures average latency value using sampling. Each latency (measured in nanoseconds) is recorded and added to the total latencies. When getValue() is called the average is calculated and returned, resetting the measurement.

Throughput and latency are not directly inversely proportional, but can be related by the formula: Throughput = 1 / (Latency + Processing Time)

If Processing Time is negligible or close to zero, then a latency of 100 milliseconds is: Throughput = 1 / (100 milliseconds) ≈ 10 writes per second

DEPRECATED: Use Micrometer Timer which provides comprehensive latency metrics (count, total time, max, percentiles, histogram).

Migration Guide:


 // OLD:
 LatencyGauge latency = new LatencyGauge();
 long start = System.nanoTime();
 // ... operation ...
 latency.set(System.nanoTime() - start);
 Long avgLatency = latency.getValue();

 // NEW:
 Timer timer = Timer.builder("operation_duration")
     .tags(tags)
     .description("Duration of operation")
     .register(meterRegistry);

 // Option 1: Lambda style
 timer.record(() -> {
     // ... operation ...
 });

 // Option 2: Timer.Sample (for async operations)
 Timer.Sample sample = Timer.start();
 // ... operation ...
 sample.stop(timer);

 // Access metrics:
 long count = timer.count();
 double totalTime = timer.totalTime(TimeUnit.NANOSECONDS);
 double mean = timer.mean(TimeUnit.NANOSECONDS);
 double max = timer.max(TimeUnit.NANOSECONDS);
 
Since:
16.5
Author:
Moran
See Also:
  • Timer
  • Constructor Details

    • LatencyGauge

      public LatencyGauge()
      Deprecated.
  • Method Details

    • recordValue

      public void recordValue(long latencyNanos)
      Deprecated.
      Parameters:
      latencyNanos - latency of operation in nanoseconds
    • getValue

      public Long getValue() throws Exception
      Deprecated.
      Description copied from class: Gauge
      Returns the metric's current value.
      Specified by:
      getValue in class Gauge<Long>
      Returns:
      the average latency in nanoseconds since the last call to getCount
      Throws:
      Exception