mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 05:48:31 +00:00
Add database size metric
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
key::{BeaconChainKey, LocalMetricsKey, MetricsRegistryKey},
|
||||
key::{BeaconChainKey, DBPathKey, LocalMetricsKey, MetricsRegistryKey},
|
||||
map_persistent_err_to_500,
|
||||
};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
@@ -7,6 +7,7 @@ use iron::prelude::*;
|
||||
use iron::{status::Status, Handler, IronResult, Request, Response};
|
||||
use persistent::Read;
|
||||
use prometheus::{Encoder, Registry, TextEncoder};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use local_metrics::LocalMetrics;
|
||||
@@ -16,6 +17,7 @@ mod local_metrics;
|
||||
/// Yields a handler for the metrics endpoint.
|
||||
pub fn build_handler<T: BeaconChainTypes + 'static>(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
db_path: PathBuf,
|
||||
metrics_registry: Registry,
|
||||
) -> impl Handler {
|
||||
let mut chain = Chain::new(handle_metrics::<T>);
|
||||
@@ -26,6 +28,7 @@ pub fn build_handler<T: BeaconChainTypes + 'static>(
|
||||
chain.link(Read::<BeaconChainKey<T>>::both(beacon_chain));
|
||||
chain.link(Read::<MetricsRegistryKey>::both(metrics_registry));
|
||||
chain.link(Read::<LocalMetricsKey>::both(local_metrics));
|
||||
chain.link(Read::<DBPathKey>::both(db_path));
|
||||
|
||||
chain
|
||||
}
|
||||
@@ -46,8 +49,12 @@ fn handle_metrics<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResul
|
||||
.get::<Read<LocalMetricsKey>>()
|
||||
.map_err(map_persistent_err_to_500)?;
|
||||
|
||||
let db_path = req
|
||||
.get::<Read<DBPathKey>>()
|
||||
.map_err(map_persistent_err_to_500)?;
|
||||
|
||||
// Update metrics that are calculated on each scrape.
|
||||
local_metrics.update(&beacon_chain);
|
||||
local_metrics.update(&beacon_chain, &db_path);
|
||||
|
||||
let mut buffer = vec![];
|
||||
let encoder = TextEncoder::new();
|
||||
|
||||
Reference in New Issue
Block a user