Add extra prom beacon chain metrics

This commit is contained in:
Paul Hauner
2019-08-12 13:26:58 +10:00
parent 6150f0ae1a
commit 7140dbc45d
10 changed files with 233 additions and 11 deletions

View File

@@ -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`.

View 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)
}