mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(metrics): Add cumulative transaction counters to improve observability (#12273)
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
use crate::Tables;
|
use crate::Tables;
|
||||||
use metrics::{Gauge, Histogram};
|
use metrics::Histogram;
|
||||||
use reth_metrics::{metrics::Counter, Metrics};
|
use reth_metrics::{metrics::Counter, Metrics};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@ -259,17 +259,19 @@ impl Labels {
|
|||||||
#[derive(Metrics, Clone)]
|
#[derive(Metrics, Clone)]
|
||||||
#[metrics(scope = "database.transaction")]
|
#[metrics(scope = "database.transaction")]
|
||||||
pub(crate) struct TransactionMetrics {
|
pub(crate) struct TransactionMetrics {
|
||||||
/// Total number of currently open database transactions
|
/// Total number of opened database transactions (cumulative)
|
||||||
open_total: Gauge,
|
opened_total: Counter,
|
||||||
|
/// Total number of closed database transactions (cumulative)
|
||||||
|
closed_total: Counter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransactionMetrics {
|
impl TransactionMetrics {
|
||||||
pub(crate) fn record_open(&self) {
|
pub(crate) fn record_open(&self) {
|
||||||
self.open_total.increment(1.0);
|
self.opened_total.increment(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn record_close(&self) {
|
pub(crate) fn record_close(&self) {
|
||||||
self.open_total.decrement(1.0);
|
self.closed_total.increment(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1724,15 +1724,29 @@
|
|||||||
},
|
},
|
||||||
"editorMode": "code",
|
"editorMode": "code",
|
||||||
"exemplar": false,
|
"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",
|
"format": "time_series",
|
||||||
"instant": false,
|
"instant": false,
|
||||||
"legendFormat": "{{mode}}",
|
"legendFormat": "Opened {{mode}}",
|
||||||
"range": true,
|
"range": true,
|
||||||
"refId": "A"
|
"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"
|
"type": "timeseries"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user