Skip to content

Commit

Permalink
fix(bin): make db metrics a gauge instead of counter (paradigmxyz#4324)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Aug 23, 2023
1 parent 77621fa commit 5a7a57d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bin/reth/src/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
use metrics::gauge;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
use metrics_util::layers::{PrefixLayer, Stack};
use reth_db::{database::Database, tables, DatabaseEnv};
use reth_metrics::metrics::{absolute_counter, describe_counter, Unit};
use reth_metrics::metrics::{describe_counter, Unit};
use std::{convert::Infallible, net::SocketAddr, sync::Arc};

pub(crate) trait Hook: Fn() + Send + Sync {}
Expand Down Expand Up @@ -93,11 +94,11 @@ pub(crate) async fn initialize(
let table_size = page_size * num_pages;
let entries = stats.entries();

absolute_counter!("db.table_size", table_size as u64, "table" => table);
absolute_counter!("db.table_pages", leaf_pages as u64, "table" => table, "type" => "leaf");
absolute_counter!("db.table_pages", branch_pages as u64, "table" => table, "type" => "branch");
absolute_counter!("db.table_pages", overflow_pages as u64, "table" => table, "type" => "overflow");
absolute_counter!("db.table_entries", entries as u64, "table" => table);
gauge!("db.table_size", table_size as f64, "table" => table);
gauge!("db.table_pages", leaf_pages as f64, "table" => table, "type" => "leaf");
gauge!("db.table_pages", branch_pages as f64, "table" => table, "type" => "branch");
gauge!("db.table_pages", overflow_pages as f64, "table" => table, "type" => "overflow");
gauge!("db.table_entries", entries as f64, "table" => table);
}

Ok::<(), eyre::Report>(())
Expand Down Expand Up @@ -126,7 +127,6 @@ pub(crate) async fn initialize(
#[cfg(all(feature = "jemalloc", unix))]
fn collect_memory_stats() {
use jemalloc_ctl::{epoch, stats};
use reth_metrics::metrics::gauge;
use tracing::error;

if epoch::advance().map_err(|error| error!(?error, "Failed to advance jemalloc epoch")).is_err()
Expand Down

0 comments on commit 5a7a57d

Please sign in to comment.