Add node status http api

This commit is contained in:
Dominik Werder
2021-05-12 09:09:19 +02:00
parent 033bf22609
commit 3df25e7a75
6 changed files with 82 additions and 3 deletions

View File

@@ -34,6 +34,9 @@ async fn go() -> Result<(), Error> {
retrieval::run_node(node_config.clone()).await?;
}
SubCmd::Client(client) => match client.client_type {
ClientType::Status(opts) => {
retrieval::client::status(opts.host, opts.port).await?;
}
ClientType::Binned(opts) => {
let beg = opts.beg.parse()?;
let end = opts.end.parse()?;

View File

@@ -31,6 +31,15 @@ pub struct Client {
#[derive(Debug, Clap)]
pub enum ClientType {
Binned(BinnedClient),
Status(StatusClient),
}
#[derive(Debug, Clap)]
pub struct StatusClient {
#[clap(long)]
pub host: String,
#[clap(long)]
pub port: u16,
}
#[derive(Debug, Clap)]

View File

@@ -10,6 +10,28 @@ use hyper::Body;
use netpod::log::*;
use netpod::PerfOpts;
pub async fn status(host: String, port: u16) -> Result<(), Error> {
let t1 = Utc::now();
let uri = format!("http://{}:{}/api/1/node_status", host, port,);
let req = hyper::Request::builder()
.method(http::Method::GET)
.uri(uri)
.body(Body::empty())?;
let client = hyper::Client::new();
let res = client.request(req).await?;
if res.status() != StatusCode::OK {
error!("Server error {:?}", res);
return Err(Error::with_msg(format!("Server error {:?}", res)));
}
let body = hyper::body::to_bytes(res.into_body()).await?;
let res = String::from_utf8(body.to_vec())?;
let t2 = chrono::Utc::now();
let ms = t2.signed_duration_since(t1).num_milliseconds() as u64;
info!("node_status DONE duration: {} ms", ms);
println!("{}", res);
Ok(())
}
pub async fn get_binned(
host: String,
port: u16,