mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 04:48:21 +00:00
Add extra prom beacon chain metrics
This commit is contained in:
@@ -7,18 +7,22 @@
|
||||
//!
|
||||
//! Provides a simple API for storing/retrieving all types that sometimes needs type-hints. See
|
||||
//! tests for implementation examples.
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
mod block_at_slot;
|
||||
mod errors;
|
||||
mod impls;
|
||||
mod leveldb_store;
|
||||
mod memory_store;
|
||||
mod metrics;
|
||||
|
||||
pub mod iter;
|
||||
|
||||
pub use self::leveldb_store::LevelDB as DiskStore;
|
||||
pub use self::memory_store::MemoryStore;
|
||||
pub use errors::Error;
|
||||
pub use metrics::scrape_for_metrics;
|
||||
pub use types::*;
|
||||
|
||||
/// An object capable of storing and retrieving objects implementing `StoreItem`.
|
||||
|
||||
25
beacon_node/store/src/metrics.rs
Normal file
25
beacon_node/store/src/metrics.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
pub use lighthouse_metrics::{set_gauge, try_create_int_gauge, *};
|
||||
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DISK_DB_SIZE: Result<IntGauge> =
|
||||
try_create_int_gauge("database_size", "Size of the on-disk database (bytes)");
|
||||
}
|
||||
|
||||
/// Updates the global metrics registry with store-related information.
|
||||
pub fn scrape_for_metrics(db_path: &PathBuf) {
|
||||
let db_size = if let Ok(iter) = fs::read_dir(db_path) {
|
||||
iter.filter_map(std::result::Result::ok)
|
||||
.map(size_of_dir_entry)
|
||||
.fold(0_u64, |sum, val| sum + val)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
set_gauge(&DISK_DB_SIZE, db_size as i64);
|
||||
}
|
||||
|
||||
fn size_of_dir_entry(dir: fs::DirEntry) -> u64 {
|
||||
dir.metadata().map(|m| m.len()).unwrap_or(0)
|
||||
}
|
||||
Reference in New Issue
Block a user