Skip to content

Commit

Permalink
Adding throughput as a histogram metric for Prometheus.
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuter committed Aug 8, 2022
1 parent bbc508c commit 2e0efef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ impl BenchRunReportItem {
"p90".to_string(),
latency.percentile(90.0).unwrap_or_default(),
),
(
"p95".to_string(),
latency.percentile(95.0).unwrap_or_default(),
),
(
"p99".to_string(),
latency.percentile(99.0).unwrap_or_default(),
Expand Down Expand Up @@ -440,6 +444,7 @@ mod tests {
assert_eq!(Some(("Min".to_string(), 0)), items.next());
assert_eq!(Some(("p50".to_string(), 500)), items.next());
assert_eq!(Some(("p90".to_string(), 900)), items.next());
assert_eq!(Some(("p95".to_string(), 950)), items.next());
assert_eq!(Some(("p99".to_string(), 990)), items.next());
assert_eq!(Some(("p99.9".to_string(), 999)), items.next());
assert_eq!(Some(("p99.99".to_string(), 999)), items.next());
Expand Down Expand Up @@ -472,6 +477,7 @@ mod tests {
assert_eq!(Some(("Min".to_string(), 0)), items.next());
assert_eq!(Some(("p50".to_string(), 500)), items.next());
assert_eq!(Some(("p90".to_string(), 900)), items.next());
assert_eq!(Some(("p95".to_string(), 950)), items.next());
assert_eq!(Some(("p99".to_string(), 990)), items.next());
assert_eq!(Some(("p99.9".to_string(), 999)), items.next());
assert_eq!(Some(("p99.99".to_string(), 999)), items.next());
Expand All @@ -491,6 +497,7 @@ mod tests {
assert_eq!(Some(("Min".to_string(), 0)), items.next());
assert_eq!(Some(("p50".to_string(), 500)), items.next());
assert_eq!(Some(("p90".to_string(), 900)), items.next());
assert_eq!(Some(("p95".to_string(), 950)), items.next());
assert_eq!(Some(("p99".to_string(), 990)), items.next());
assert_eq!(Some(("p99.9".to_string(), 998)), items.next());
assert_eq!(Some(("p99.99".to_string(), 998)), items.next());
Expand All @@ -508,6 +515,7 @@ mod tests {
assert_eq!(Some(("Min".to_string(), 1)), items.next());
assert_eq!(Some(("p50".to_string(), 501)), items.next());
assert_eq!(Some(("p90".to_string(), 901)), items.next());
assert_eq!(Some(("p95".to_string(), 951)), items.next());
assert_eq!(Some(("p99".to_string(), 991)), items.next());
assert_eq!(Some(("p99.9".to_string(), 999)), items.next());
assert_eq!(Some(("p99.99".to_string(), 999)), items.next());
Expand Down Expand Up @@ -559,6 +567,7 @@ mod tests {
assert!(as_str.contains("Min"));
assert!(as_str.contains("p50"));
assert!(as_str.contains("p90"));
assert!(as_str.contains("p95"));
assert!(as_str.contains("p99"));
assert!(as_str.contains("p99.9"));
assert!(as_str.contains("p99.99"));
Expand Down
7 changes: 6 additions & 1 deletion src/prometheus_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ impl PrometheusReporter {
"p90".to_string(),
histogram.percentile(90.0).unwrap_or_default(),
),
(
"p95".to_string(),
histogram.percentile(95.0).unwrap_or_default(),
),
(
"p99".to_string(),
histogram.percentile(99.0).unwrap_or_default(),
Expand Down Expand Up @@ -318,7 +322,7 @@ mod test {

let metrics = registry.gather();

assert_eq!(13, metrics.len());
assert_eq!(14, metrics.len());
assert_eq!("latency", metrics[0].get_name());
assert_eq!("Latency of requests", metrics[0].get_help());
assert_eq!(MetricType::HISTOGRAM, metrics[0].get_field_type());
Expand All @@ -337,6 +341,7 @@ mod test {
"latency_min",
"latency_p50",
"latency_p90",
"latency_p95",
"latency_p99",
"latency_p99_9",
"latency_p99_99",
Expand Down

0 comments on commit 2e0efef

Please sign in to comment.