add experimental rrd api to get cpu stats
This commit is contained in:
@ -9,11 +9,13 @@ mod syslog;
|
||||
mod journal;
|
||||
mod services;
|
||||
mod status;
|
||||
mod rrd;
|
||||
|
||||
pub const SUBDIRS: SubdirMap = &[
|
||||
("dns", &dns::ROUTER),
|
||||
("journal", &journal::ROUTER),
|
||||
("network", &network::ROUTER),
|
||||
("rrd", &rrd::ROUTER),
|
||||
("services", &services::ROUTER),
|
||||
("status", &status::ROUTER),
|
||||
("syslog", &syslog::ROUTER),
|
||||
|
34
src/api2/node/rrd.rs
Normal file
34
src/api2/node/rrd.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox::api::{api, Router};
|
||||
|
||||
use crate::api2::types::*;
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
node: {
|
||||
schema: NODE_SCHEMA,
|
||||
},
|
||||
timeframe: {
|
||||
type: RRDTimeFrameResolution,
|
||||
},
|
||||
cf: {
|
||||
type: RRDMode,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// Read CPU stats
|
||||
fn get_cpu_stats(
|
||||
timeframe: RRDTimeFrameResolution,
|
||||
cf: RRDMode,
|
||||
_param: Value,
|
||||
) -> Result<Value, Error> {
|
||||
|
||||
crate::rrd::extract_data("host/cpu", timeframe, cf)
|
||||
}
|
||||
|
||||
pub const ROUTER: Router = Router::new()
|
||||
.get(&API_METHOD_GET_CPU_STATS);
|
@ -878,3 +878,31 @@ fn test_proxmox_user_id_schema() -> Result<(), anyhow::Error> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[api()]
|
||||
#[derive(Copy, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "UPPERCASE")]
|
||||
pub enum RRDMode {
|
||||
/// Maximum
|
||||
Max,
|
||||
/// Average
|
||||
Average,
|
||||
}
|
||||
|
||||
|
||||
#[api()]
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum RRDTimeFrameResolution {
|
||||
/// 1 min => last 70 minutes
|
||||
Hour = 60,
|
||||
/// 30 min => last 35 hours
|
||||
Day = 60*30,
|
||||
/// 3 hours => about 8 days
|
||||
Week = 60*180,
|
||||
/// 12 hours => last 35 days
|
||||
Month = 60*720,
|
||||
/// 1 week => last 490 days
|
||||
Year = 60*10080,
|
||||
}
|
||||
|
Reference in New Issue
Block a user