replace serde with miniserde
This commit is contained in:
parent
fcd49eb3be
commit
aa6a8f1c74
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<dyn error::Error>;
|
||||
@ -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<StatError> for Error {
|
||||
@ -57,11 +53,6 @@ impl From<StatError> 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, StatError> {
|
||||
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<String, StatError> {
|
||||
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<String, StatError> {
|
||||
};
|
||||
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<String, StatError> {
|
||||
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<String, StatError> {
|
||||
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<String, StatError> {
|
||||
pub fn uptime() -> Result<String, StatError> {
|
||||
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)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use serde::Serialize;
|
||||
use miniserde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CpuStat {
|
||||
|
Loading…
Reference in New Issue
Block a user