Begin metrics refactor

This commit is contained in:
Paul Hauner
2019-08-11 12:12:19 +10:00
parent 4020d13064
commit 48733917be
7 changed files with 46 additions and 1 deletions

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