mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Begin metrics refactor
This commit is contained in:
@@ -3,6 +3,7 @@ extern crate hyper;
|
||||
mod beacon;
|
||||
mod config;
|
||||
mod helpers;
|
||||
mod metrics;
|
||||
mod node;
|
||||
mod url_query;
|
||||
|
||||
@@ -103,6 +104,7 @@ pub fn start_server<T: BeaconChainTypes + Clone + 'static>(
|
||||
let result = match (req.method(), path.as_ref()) {
|
||||
(&Method::GET, "/beacon/state") => beacon::get_state::<T>(req),
|
||||
(&Method::GET, "/beacon/state_root") => beacon::get_state_root::<T>(req),
|
||||
(&Method::GET, "/metrics") => metrics::get_prometheus(req),
|
||||
(&Method::GET, "/node/version") => node::get_version(req),
|
||||
(&Method::GET, "/node/genesis_time") => node::get_genesis_time::<T>(req),
|
||||
_ => Err(ApiError::MethodNotAllowed(path.clone())),
|
||||
|
||||
17
beacon_node/rest_api/src/metrics.rs
Normal file
17
beacon_node/rest_api/src/metrics.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::{success_response, ApiError, ApiResult};
|
||||
use hyper::{Body, Request};
|
||||
use prometheus::{Encoder, TextEncoder};
|
||||
|
||||
/// Returns the full set of Prometheus metrics for the Beacon Node application.
|
||||
pub fn get_prometheus(_req: Request<Body>) -> ApiResult {
|
||||
let mut buffer = vec![];
|
||||
let encoder = TextEncoder::new();
|
||||
|
||||
encoder
|
||||
.encode(&beacon_chain::gather_metrics(), &mut buffer)
|
||||
.unwrap();
|
||||
|
||||
String::from_utf8(buffer)
|
||||
.map(|string| success_response(Body::from(string)))
|
||||
.map_err(|e| ApiError::ServerError(format!("Failed to encode prometheus info: {:?}", e)))
|
||||
}
|
||||
Reference in New Issue
Block a user