Add /node/health endpoint (#1197)

* Start adding health endpoint

* Use psutil more

* Add get_health test

* Expose health to Prom

* Update comments

* Add /node/health to docs

* Update Prom naming
This commit is contained in:
Paul Hauner
2020-05-28 11:24:24 +10:00
committed by GitHub
parent 58a9f979e0
commit ea4a52984c
9 changed files with 181 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
use crate::response_builder::ResponseBuilder;
use crate::ApiResult;
use crate::{ApiError, ApiResult};
use eth2_libp2p::{types::SyncState, NetworkGlobals};
use hyper::{Body, Request};
use rest_types::{SyncingResponse, SyncingStatus};
use rest_types::{Health, SyncingResponse, SyncingStatus};
use std::sync::Arc;
use types::{EthSpec, Slot};
use version;
@@ -41,3 +41,9 @@ pub fn syncing<T: EthSpec>(
sync_status,
})
}
pub fn get_health(req: Request<Body>) -> ApiResult {
let health = Health::observe().map_err(|e| ApiError::ServerError(e))?;
ResponseBuilder::new(&req)?.body_no_ssz(&health)
}