Add extra metrics for prom
This commit is contained in:
parent
3e73a008eb
commit
e756a0aaa4
@ -29,16 +29,22 @@ fn handle_metrics<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResul
|
|||||||
|
|
||||||
let r = Registry::new();
|
let r = Registry::new();
|
||||||
|
|
||||||
let present_slot = if let Ok(Some(slot)) = beacon_chain.slot_clock.present_slot() {
|
let present_slot = beacon_chain
|
||||||
slot
|
.slot_clock
|
||||||
} else {
|
.present_slot()
|
||||||
Slot::new(0)
|
.unwrap_or_else(|_| None)
|
||||||
};
|
.unwrap_or_else(|| Slot::new(0));
|
||||||
register_and_set_slot(
|
register_and_set_slot(&r, "present_slot", "slock_clock_reading", present_slot);
|
||||||
|
|
||||||
|
let best_slot = beacon_chain.head().beacon_block.slot;
|
||||||
|
register_and_set_slot(&r, "best_slot", "slot_of_block_at_head_of_chain", best_slot);
|
||||||
|
|
||||||
|
let validator_count = beacon_chain.head().beacon_state.validator_registry.len();
|
||||||
|
register_and_set(
|
||||||
&r,
|
&r,
|
||||||
"present_slot",
|
"validator_count",
|
||||||
"direct_slock_clock_reading",
|
"total_number_of_validators",
|
||||||
present_slot,
|
validator_count as i64,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Gather the metrics.
|
// Gather the metrics.
|
||||||
@ -52,6 +58,13 @@ fn handle_metrics<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResul
|
|||||||
Ok(Response::with((Status::Ok, prom_string)))
|
Ok(Response::with((Status::Ok, prom_string)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn register_and_set(registry: &Registry, name: &str, help: &str, value: i64) {
|
||||||
|
let counter_opts = Opts::new(name, help);
|
||||||
|
let counter = IntCounter::with_opts(counter_opts).unwrap();
|
||||||
|
registry.register(Box::new(counter.clone())).unwrap();
|
||||||
|
counter.inc_by(value);
|
||||||
|
}
|
||||||
|
|
||||||
fn register_and_set_slot(registry: &Registry, name: &str, help: &str, slot: Slot) {
|
fn register_and_set_slot(registry: &Registry, name: &str, help: &str, slot: Slot) {
|
||||||
let counter_opts = Opts::new(name, help);
|
let counter_opts = Opts::new(name, help);
|
||||||
let counter = IntCounter::with_opts(counter_opts).unwrap();
|
let counter = IntCounter::with_opts(counter_opts).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user