Skip to content

Commit

Permalink
docs: adjust metrics documentation
Browse files Browse the repository at this point in the history
Inform that metrics may now only be used under crate feature 'metrics'.
Mention new metrics in documentation and show an example
how to collect them.
Adjust examples to include new metrics.
  • Loading branch information
QuerthDP authored and NikodemGapski committed Jan 14, 2025
1 parent db9d17b commit 7be0e38
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/source/metrics/metrics.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Driver metrics

This feature is available only under the crate feature `metrics`.

During operation the driver collects various metrics.

They can be accessed at any moment using `Session::get_metrics()`
Expand All @@ -11,6 +13,9 @@ They can be accessed at any moment using `Session::get_metrics()`
* Total number of paged queries
* Number of errors during paged queries
* Number of retries
* Latency histogram statistics (min, max, mean, standard deviation, percentiles)
* Rates of queries per second in various time frames
* Number of active connections, and connection and request timeouts

### Example
```rust
Expand All @@ -29,6 +34,27 @@ println!(
"99.9 latency percentile: {}",
metrics.get_latency_percentile_ms(99.9).unwrap()
);

let snapshot = metrics.get_snapshot().unwrap();
println!("Min: {}", snapshot.min);
println!("Max: {}", snapshot.max);
println!("Mean: {}", snapshot.mean);
println!("Standard deviation: {}", snapshot.stddev);
println!("Median: {}", snapshot.median);
println!("75th percentile: {}", snapshot.percentile_75);
println!("95th percentile: {}", snapshot.percentile_95);
println!("98th percentile: {}", snapshot.percentile_98);
println!("99th percentile: {}", snapshot.percentile_99);
println!("99.9th percentile: {}", snapshot.percentile_99_9);

println!("Mean rate: {}", metrics.get_mean_rate());
println!("One minute rate: {}", metrics.get_one_minute_rate());
println!("Five minute rate: {}", metrics.get_five_minute_rate());
println!("Fifteen minute rate: {}", metrics.get_fifteen_minute_rate());

println!("Total connections: {}", metrics.get_total_connections());
println!("Connection timeouts: {}", metrics.get_connection_timeouts());
println!("Requests timeouts: {}", metrics.get_request_timeouts());
# Ok(())
# }
```
21 changes: 21 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ async fn main() -> Result<()> {
metrics.get_latency_percentile_ms(99.9).unwrap()
);

let snapshot = metrics.get_snapshot().unwrap();
println!("Min: {}", snapshot.min);
println!("Max: {}", snapshot.max);
println!("Mean: {}", snapshot.mean);
println!("Standard deviation: {}", snapshot.stddev);
println!("Median: {}", snapshot.median);
println!("75th percentile: {}", snapshot.percentile_75);
println!("95th percentile: {}", snapshot.percentile_95);
println!("98th percentile: {}", snapshot.percentile_98);
println!("99th percentile: {}", snapshot.percentile_99);
println!("99.9th percentile: {}", snapshot.percentile_99_9);

println!("Mean rate: {}", metrics.get_mean_rate());
println!("One minute rate: {}", metrics.get_one_minute_rate());
println!("Five minute rate: {}", metrics.get_five_minute_rate());
println!("Fifteen minute rate: {}", metrics.get_fifteen_minute_rate());

println!("Total connections: {}", metrics.get_total_connections());
println!("Connection timeouts: {}", metrics.get_connection_timeouts());
println!("Requests timeouts: {}", metrics.get_request_timeouts());

println!("Ok.");

Ok(())
Expand Down

0 comments on commit 7be0e38

Please sign in to comment.