diff --git a/peach-stats/Cargo.toml b/peach-stats/Cargo.toml index b603d20..82b9c95 100644 --- a/peach-stats/Cargo.toml +++ b/peach-stats/Cargo.toml @@ -33,8 +33,7 @@ jsonrpc-core = "11" jsonrpc-http-server = "11" jsonrpc-test = "11" log = "0.4" +miniserde = "0.1.15" probes = "0.3" -serde = { version = "1", features = ["derive"] } -serde_json = "1" snafu = "0.4" systemstat = "0.1" diff --git a/peach-stats/README.md b/peach-stats/README.md index f187a53..b2d527e 100644 --- a/peach-stats/README.md +++ b/peach-stats/README.md @@ -14,7 +14,7 @@ System statistics microservice module for PeachCloud. Provides a JSON-RPC wrappe | `load_average` | Load average statistics | `one`, `five`, `fifteen` | | `mem_stats` | Memory statistics | `total`, `free`, `used` | | `ping` | Microservice status | `success` if running | -| `uptime` | System uptime | `secs`, `nanos` | +| `uptime` | System uptime | `secs` | ### Environment @@ -101,7 +101,7 @@ With microservice running, open a second terminal window and use `curl` to call Server responds with: -`{"jsonrpc":"2.0","result":"{\"secs\":840968,\"nanos\":0}","id":1}` +`{"jsonrpc":"2.0","result":"{\"secs\":840968}","id":1}` ### Licensing diff --git a/peach-stats/src/error.rs b/peach-stats/src/error.rs index 12ce99d..53ba6a1 100644 --- a/peach-stats/src/error.rs +++ b/peach-stats/src/error.rs @@ -2,7 +2,6 @@ use std::{error, io}; use jsonrpc_core::{types::error::Error, ErrorCode}; use probes::ProbeError; -use serde_json::Error as SerdeError; use snafu::Snafu; pub type BoxError = Box; @@ -24,9 +23,6 @@ pub enum StatError { #[snafu(display("Failed to retrieve system uptime: {}", source))] ReadUptime { source: io::Error }, - - #[snafu(display("JSON serialization failed: {}", source))] - SerdeSerialize { source: SerdeError }, } impl From for Error { @@ -57,11 +53,6 @@ impl From for Error { message: format!("Failed to retrieve system uptime: {}", source), data: None, }, - StatError::SerdeSerialize { source } => Error { - code: ErrorCode::ServerError(-32002), - message: format!("JSON serialization failed: {}", source), - data: None, - }, } } } diff --git a/peach-stats/src/stats.rs b/peach-stats/src/stats.rs index a3c42bb..f539410 100644 --- a/peach-stats/src/stats.rs +++ b/peach-stats/src/stats.rs @@ -1,5 +1,6 @@ use std::result::Result; +use miniserde::json; use probes::{cpu, disk_usage, load, memory}; use snafu::ResultExt; use systemstat::{Platform, System}; @@ -16,7 +17,7 @@ pub fn cpu_stats() -> Result { nice: s.nice, idle: s.idle, }; - let json_cpu = serde_json::to_string(&cpu).context(SerdeSerialize)?; + let json_cpu = json::to_string(&cpu); Ok(json_cpu) } @@ -30,7 +31,7 @@ pub fn cpu_stats_percent() -> Result { nice: s.nice, idle: s.idle, }; - let json_cpu = serde_json::to_string(&cpu).context(SerdeSerialize)?; + let json_cpu = json::to_string(&cpu); Ok(json_cpu) } @@ -49,7 +50,7 @@ pub fn disk_usage() -> Result { }; disk_usages.push(disk); } - let json_disks = serde_json::to_string(&disk_usages).context(SerdeSerialize)?; + let json_disks = json::to_string(&disk_usages); Ok(json_disks) } @@ -61,7 +62,7 @@ pub fn load_average() -> Result { five: l.five, fifteen: l.fifteen, }; - let json_load_avg = serde_json::to_string(&load_avg).context(SerdeSerialize)?; + let json_load_avg = json::to_string(&load_avg); Ok(json_load_avg) } @@ -73,7 +74,7 @@ pub fn mem_stats() -> Result { free: m.free(), used: m.used(), }; - let json_mem = serde_json::to_string(&mem).context(SerdeSerialize)?; + let json_mem = json::to_string(&mem); Ok(json_mem) } @@ -81,7 +82,8 @@ pub fn mem_stats() -> Result { pub fn uptime() -> Result { let sys = System::new(); let uptime = sys.uptime().context(ReadUptime)?; - let json_uptime = serde_json::to_string(&uptime).context(SerdeSerialize)?; + let uptime_secs = uptime.as_secs(); + let json_uptime = json::to_string(&uptime_secs); Ok(json_uptime) } diff --git a/peach-stats/src/structs.rs b/peach-stats/src/structs.rs index 1fe12ee..f307879 100644 --- a/peach-stats/src/structs.rs +++ b/peach-stats/src/structs.rs @@ -1,4 +1,4 @@ -use serde::Serialize; +use miniserde::Serialize; #[derive(Debug, Serialize)] pub struct CpuStat {