Skip to content

Commit

Permalink
feat(metrics): Add cumulative transaction counters to improve observa…
Browse files Browse the repository at this point in the history
…bility (paradigmxyz#12273)

Co-authored-by: Dan Cline <[email protected]>
  • Loading branch information
hoank101 and Rjected authored Dec 30, 2024
1 parent 5629ba0 commit 4110493
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 7 additions & 5 deletions crates/storage/db/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Tables;
use metrics::{Gauge, Histogram};
use metrics::Histogram;
use reth_metrics::{metrics::Counter, Metrics};
use rustc_hash::FxHashMap;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -259,17 +259,19 @@ impl Labels {
#[derive(Metrics, Clone)]
#[metrics(scope = "database.transaction")]
pub(crate) struct TransactionMetrics {
/// Total number of currently open database transactions
open_total: Gauge,
/// Total number of opened database transactions (cumulative)
opened_total: Counter,
/// Total number of closed database transactions (cumulative)
closed_total: Counter,
}

impl TransactionMetrics {
pub(crate) fn record_open(&self) {
self.open_total.increment(1.0);
self.opened_total.increment(1);
}

pub(crate) fn record_close(&self) {
self.open_total.decrement(1.0);
self.closed_total.increment(1);
}
}

Expand Down
20 changes: 17 additions & 3 deletions etc/grafana/dashboards/overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -1724,15 +1724,29 @@
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(reth_database_transaction_open_total{instance=~\"$instance\"}) by (mode)",
"expr": "sum(reth_database_transaction_opened_total{instance=~\"$instance\"}) by (mode)",
"format": "time_series",
"instant": false,
"legendFormat": "{{mode}}",
"legendFormat": "Opened {{mode}}",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(reth_database_transaction_closed_total{instance=~\"$instance\"}) by (mode)",
"format": "time_series",
"instant": false,
"legendFormat": "Closed {{mode}}",
"range": true,
"refId": "B"
}
],
"title": "Number of open transactions",
"title": "Number of transactions",
"type": "timeseries"
},
{
Expand Down

0 comments on commit 4110493

Please sign in to comment.