mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Merge pull request #544 from romanz/db-size
Expose index DB size as a Prometheus gauge metric
This commit is contained in:
commit
6755b4c7f1
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -342,6 +342,7 @@ dependencies = [
|
|||||||
"dirs-next",
|
"dirs-next",
|
||||||
"electrs-rocksdb",
|
"electrs-rocksdb",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"fs_extra",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
@ -423,6 +424,12 @@ dependencies = [
|
|||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fs_extra"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fuchsia-cprng"
|
name = "fuchsia-cprng"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -28,6 +28,7 @@ configure_me = "0.4"
|
|||||||
crossbeam-channel = "0.5"
|
crossbeam-channel = "0.5"
|
||||||
dirs-next = "2.0"
|
dirs-next = "2.0"
|
||||||
env_logger = "0.7"
|
env_logger = "0.7"
|
||||||
|
fs_extra = "1.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
parking_lot = "0.11"
|
parking_lot = "0.11"
|
||||||
prometheus = { version = "0.13", optional = true }
|
prometheus = { version = "0.13", optional = true }
|
||||||
|
@ -269,6 +269,10 @@ impl DBStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_size(&self) -> Result<u64> {
|
||||||
|
fs_extra::dir::get_size(self.db.path()).context("failed to get DB size")
|
||||||
|
}
|
||||||
|
|
||||||
fn start_compactions(&self) {
|
fn start_compactions(&self) {
|
||||||
self.bulk_import.store(false, Ordering::Relaxed);
|
self.bulk_import.store(false, Ordering::Relaxed);
|
||||||
for name in COLUMN_FAMILIES {
|
for name in COLUMN_FAMILIES {
|
||||||
|
@ -16,6 +16,7 @@ struct Stats {
|
|||||||
update_duration: Histogram,
|
update_duration: Histogram,
|
||||||
update_size: Histogram,
|
update_size: Histogram,
|
||||||
height: Gauge,
|
height: Gauge,
|
||||||
|
db_size: Gauge,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stats {
|
impl Stats {
|
||||||
@ -34,6 +35,7 @@ impl Stats {
|
|||||||
metrics::default_size_buckets(),
|
metrics::default_size_buckets(),
|
||||||
),
|
),
|
||||||
height: metrics.gauge("index_height", "Latest indexed block height"),
|
height: metrics.gauge("index_height", "Latest indexed block height"),
|
||||||
|
db_size: metrics.gauge("index_db_size", "Index DB size (bytes)"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +91,8 @@ impl Index {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stats = Stats::new(metrics);
|
let stats = Stats::new(metrics);
|
||||||
stats.height.set(chain.height());
|
stats.height.set(chain.height() as f64);
|
||||||
|
stats.db_size.set(store.get_size()? as f64);
|
||||||
|
|
||||||
Ok(Index {
|
Ok(Index {
|
||||||
store,
|
store,
|
||||||
@ -166,6 +169,7 @@ impl Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn sync(&mut self, daemon: &Daemon, exit_flag: &ExitFlag) -> Result<()> {
|
pub(crate) fn sync(&mut self, daemon: &Daemon, exit_flag: &ExitFlag) -> Result<()> {
|
||||||
|
self.stats.db_size.set(self.store.get_size()? as f64);
|
||||||
loop {
|
loop {
|
||||||
let new_headers =
|
let new_headers =
|
||||||
self.observe_duration("headers", || daemon.get_new_headers(&self.chain))?;
|
self.observe_duration("headers", || daemon.get_new_headers(&self.chain))?;
|
||||||
@ -194,7 +198,7 @@ impl Index {
|
|||||||
self.observe_duration("block", || {
|
self.observe_duration("block", || {
|
||||||
index_single_block(block, height).extend(&mut batch)
|
index_single_block(block, height).extend(&mut batch)
|
||||||
});
|
});
|
||||||
self.stats.height.set(height);
|
self.stats.height.set(height as f64);
|
||||||
})?;
|
})?;
|
||||||
let heights: Vec<_> = heights.collect();
|
let heights: Vec<_> = heights.collect();
|
||||||
assert!(
|
assert!(
|
||||||
@ -205,6 +209,7 @@ impl Index {
|
|||||||
batch.sort();
|
batch.sort();
|
||||||
self.report_stats(&batch);
|
self.report_stats(&batch);
|
||||||
self.observe_duration("write", || self.store.write(batch));
|
self.observe_duration("write", || self.store.write(batch));
|
||||||
|
self.stats.db_size.set(self.store.get_size()? as f64);
|
||||||
}
|
}
|
||||||
self.chain.update(new_headers);
|
self.chain.update(new_headers);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ mod metrics_impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Gauge {
|
impl Gauge {
|
||||||
pub fn set(&self, value: usize) {
|
pub fn set(&self, value: f64) {
|
||||||
self.gauge.set(value as f64)
|
self.gauge.set(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ mod metrics_fake {
|
|||||||
pub struct Gauge {}
|
pub struct Gauge {}
|
||||||
|
|
||||||
impl Gauge {
|
impl Gauge {
|
||||||
pub fn set(&self, _value: usize) {}
|
pub fn set(&self, _value: f64) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user