lighthouse/beacon_node/rest_api/src/metrics.rs
2019-08-11 14:46:20 +10:00

16 lines
583 B
Rust

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(&prometheus::gather(), &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)))
}