Skip to content

Commit

Permalink
feat(prometheus): add bytes metrics as counter (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 authored Oct 9, 2023
1 parent 0995d40 commit 560f8a0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/layers/prometheus_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ struct PrometheusClientMetrics {
request_duration_seconds: Family<OperationLabels, Histogram>,
/// The histogram of bytes
bytes_histogram: Family<OperationLabels, Histogram>,
/// The counter of bytes
bytes_total: Family<OperationLabels, Counter>,
}

impl PrometheusClientMetrics {
pub fn register(registry: &mut Registry) -> Self {
let requests_total = Family::default();
let errors_total = Family::default();
let bytes_total = Family::default();
let request_duration_seconds = Family::<OperationLabels, _>::new_with_constructor(|| {
let buckets = histogram::exponential_buckets(0.01, 2.0, 16);
Histogram::new(buckets)
Expand All @@ -139,19 +142,21 @@ impl PrometheusClientMetrics {
Histogram::new(buckets)
});

registry.register("opendal_requests_total", "", requests_total.clone());
registry.register("opendal_errors_total", "", errors_total.clone());
registry.register("opendal_requests", "", requests_total.clone());
registry.register("opendal_errors", "", errors_total.clone());
registry.register(
"opendal_request_duration_seconds",
"",
request_duration_seconds.clone(),
);
registry.register("opendal_bytes_histogram", "", bytes_histogram.clone());
registry.register("opendal_bytes", "", bytes_total.clone());
Self {
requests_total,
errors_total,
request_duration_seconds,
bytes_histogram,
bytes_total,
}
}

Expand All @@ -174,6 +179,7 @@ impl PrometheusClientMetrics {
self.bytes_histogram
.get_or_create(&labels)
.observe(bytes as f64);
self.bytes_total.get_or_create(&labels).inc_by(bytes as u64);
}

fn observe_request_duration(&self, scheme: Scheme, op: Operation, duration: Duration) {
Expand Down

0 comments on commit 560f8a0

Please sign in to comment.