fred/commands/interfaces/
metrics.rs

1use crate::interfaces::ClientLike;
2
3#[cfg(feature = "metrics")]
4use crate::modules::metrics::Stats;
5
6/// Functions that implement the internal metrics interface.
7pub trait MetricsInterface: ClientLike + Sized {
8  /// Read the number of request redeliveries.
9  ///
10  /// This is the number of times a request had to be sent again due to a connection closing while waiting on a
11  /// response.
12  fn read_redelivery_count(&self) -> usize {
13    self.inner().counters.read_redelivery_count()
14  }
15
16  /// Read and reset the number of request redeliveries.
17  fn take_redelivery_count(&self) -> usize {
18    self.inner().counters.take_redelivery_count()
19  }
20
21  /// Read the number of buffered commands that have not yet been sent to the server.
22  fn command_queue_len(&self) -> usize {
23    self.inner().counters.read_cmd_buffer_len()
24  }
25
26  /// Read latency metrics across all commands.
27  ///
28  /// This metric reflects the total latency experienced by callers, including time spent waiting in memory to be
29  /// written and network latency. Features such as automatic reconnect and frame serialization time can all affect
30  /// these values.
31  #[cfg(feature = "metrics")]
32  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
33  fn read_latency_metrics(&self) -> Stats {
34    self.inner().latency_stats.read().read_metrics()
35  }
36
37  /// Read and consume latency metrics, resetting their values afterwards.
38  #[cfg(feature = "metrics")]
39  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
40  fn take_latency_metrics(&self) -> Stats {
41    self.inner().latency_stats.write().take_metrics()
42  }
43
44  /// Read network latency metrics across all commands.
45  ///
46  /// This metric only reflects time spent waiting on a response. It will factor in reconnect time if a response
47  /// doesn't arrive due to a connection closing, but it does not include the time a command spends waiting to be
48  /// written, serialization time, backpressure, etc.
49  #[cfg(feature = "metrics")]
50  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
51  fn read_network_latency_metrics(&self) -> Stats {
52    self.inner().network_latency_stats.read().read_metrics()
53  }
54
55  /// Read and consume network latency metrics, resetting their values afterwards.
56  #[cfg(feature = "metrics")]
57  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
58  fn take_network_latency_metrics(&self) -> Stats {
59    self.inner().network_latency_stats.write().take_metrics()
60  }
61
62  /// Read request payload size metrics across all commands.
63  #[cfg(feature = "metrics")]
64  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
65  fn read_req_size_metrics(&self) -> Stats {
66    self.inner().req_size_stats.read().read_metrics()
67  }
68
69  /// Read and consume request payload size metrics, resetting their values afterwards.
70  #[cfg(feature = "metrics")]
71  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
72  fn take_req_size_metrics(&self) -> Stats {
73    self.inner().req_size_stats.write().take_metrics()
74  }
75
76  /// Read response payload size metrics across all commands.
77  #[cfg(feature = "metrics")]
78  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
79  fn read_res_size_metrics(&self) -> Stats {
80    self.inner().res_size_stats.read().read_metrics()
81  }
82
83  /// Read and consume response payload size metrics, resetting their values afterwards.
84  #[cfg(feature = "metrics")]
85  #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
86  fn take_res_size_metrics(&self) -> Stats {
87    self.inner().res_size_stats.write().take_metrics()
88  }
89}