Local API
This commit is contained in:
parent
5f40158b00
commit
927c377822
6 changed files with 155 additions and 21 deletions
|
|
@ -1,5 +1,7 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use json::{JsonValue, object};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub logs: VecDeque<String>,
|
||||
|
|
@ -67,4 +69,32 @@ impl AppState {
|
|||
self.net_down.remove(0);
|
||||
}
|
||||
}
|
||||
pub fn to_json(&self) -> JsonValue {
|
||||
let json = object! {
|
||||
"cpu" => self.cpu
|
||||
.iter()
|
||||
.map(|(_, y)| *y)
|
||||
.collect::<Vec<f64>>(),
|
||||
"ram" => self.ram
|
||||
.iter()
|
||||
.map(|(_, y)| *y)
|
||||
.collect::<Vec<f64>>(),
|
||||
"ping" => self
|
||||
.ping
|
||||
.iter()
|
||||
.map(|(_, y)| *y)
|
||||
.collect::<Vec<f64>>(),
|
||||
"net_up" => self
|
||||
.net_up
|
||||
.iter()
|
||||
.map(|(_, y)| *y)
|
||||
.collect::<Vec<f64>>(),
|
||||
"net_down" => self
|
||||
.net_down
|
||||
.iter()
|
||||
.map(|(_, y)| *y)
|
||||
.collect::<Vec<f64>>(),
|
||||
};
|
||||
json
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue