Add lighthouse_metrics gather fn
This commit is contained in:
parent
d7c546844c
commit
7165598b7f
@ -46,20 +46,22 @@ pub fn get_prometheus<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
|
|||||||
// - Statically updated: things which are only updated at the time of the scrape (used where we
|
// - Statically updated: things which are only updated at the time of the scrape (used where we
|
||||||
// can avoid cluttering up code with metrics calls).
|
// can avoid cluttering up code with metrics calls).
|
||||||
//
|
//
|
||||||
// The `prometheus` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`) which
|
// The `lighthouse_metrics` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`)
|
||||||
// keeps the state of all the metrics. Dynamically updated things will already be up-to-date in
|
// which keeps the state of all the metrics. Dynamically updated things will already be
|
||||||
// the registry (because they update themselves) however statically updated things need to be
|
// up-to-date in the registry (because they update themselves) however statically updated
|
||||||
// "scraped".
|
// things need to be "scraped".
|
||||||
//
|
//
|
||||||
// We proceed by, first updating all the static metrics using `scrape_for_metrics(..)`. Then,
|
// We proceed by, first updating all the static metrics using `scrape_for_metrics(..)`. Then,
|
||||||
// using `prometheus::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into a
|
// using `lighthouse_metrics::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into
|
||||||
// string that can be returned via HTTP.
|
// a string that can be returned via HTTP.
|
||||||
|
|
||||||
slot_clock::scrape_for_metrics::<T::EthSpec, T::SlotClock>(&beacon_chain.slot_clock);
|
slot_clock::scrape_for_metrics::<T::EthSpec, T::SlotClock>(&beacon_chain.slot_clock);
|
||||||
store::scrape_for_metrics(&db_path);
|
store::scrape_for_metrics(&db_path);
|
||||||
beacon_chain::scrape_for_metrics(&beacon_chain);
|
beacon_chain::scrape_for_metrics(&beacon_chain);
|
||||||
|
|
||||||
encoder.encode(&prometheus::gather(), &mut buffer).unwrap();
|
encoder
|
||||||
|
.encode(&lighthouse_metrics::gather(), &mut buffer)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
String::from_utf8(buffer)
|
String::from_utf8(buffer)
|
||||||
.map(|string| success_response(Body::from(string)))
|
.map(|string| success_response(Body::from(string)))
|
||||||
|
@ -2,6 +2,10 @@ use prometheus::{HistogramOpts, HistogramTimer, Opts};
|
|||||||
|
|
||||||
pub use prometheus::{Histogram, IntCounter, IntGauge, Result};
|
pub use prometheus::{Histogram, IntCounter, IntGauge, Result};
|
||||||
|
|
||||||
|
pub fn gather() -> Vec<prometheus::proto::MetricFamily> {
|
||||||
|
prometheus::gather()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn try_create_int_counter(name: &str, help: &str) -> Result<IntCounter> {
|
pub fn try_create_int_counter(name: &str, help: &str) -> Result<IntCounter> {
|
||||||
let opts = Opts::new(name, help);
|
let opts = Opts::new(name, help);
|
||||||
let counter = IntCounter::with_opts(opts)?;
|
let counter = IntCounter::with_opts(opts)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user