From 0a10d99d5491eef8af63138e9e1dbc644160f1c0 Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Mon, 9 Oct 2023 18:49:11 +0800 Subject: [PATCH 1/2] add bytes metrics as counter --- core/src/layers/prometheus_client.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/layers/prometheus_client.rs b/core/src/layers/prometheus_client.rs index b08b50a28af6..18b9d68744ce 100644 --- a/core/src/layers/prometheus_client.rs +++ b/core/src/layers/prometheus_client.rs @@ -124,12 +124,15 @@ struct PrometheusClientMetrics { request_duration_seconds: Family, /// The histogram of bytes bytes_histogram: Family, + /// The counter of bytes + bytes_total: Family, } 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::::new_with_constructor(|| { let buckets = histogram::exponential_buckets(0.01, 2.0, 16); Histogram::new(buckets) @@ -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, } } @@ -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 f64); } fn observe_request_duration(&self, scheme: Scheme, op: Operation, duration: Duration) { From 4ef8b0b887a47f4d46324c4a07ea3346a6c3af2a Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Mon, 9 Oct 2023 19:08:10 +0800 Subject: [PATCH 2/2] fix lint --- core/src/layers/prometheus_client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/layers/prometheus_client.rs b/core/src/layers/prometheus_client.rs index 18b9d68744ce..e6c80d942f53 100644 --- a/core/src/layers/prometheus_client.rs +++ b/core/src/layers/prometheus_client.rs @@ -179,7 +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 f64); + self.bytes_total.get_or_create(&labels).inc_by(bytes as u64); } fn observe_request_duration(&self, scheme: Scheme, op: Operation, duration: Duration) {