api2/nodes/status: use NodeStatus struct
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
75054859ff
commit
eb70464839
|
@ -2,7 +2,7 @@ use std::process::Command;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{Error, format_err, bail};
|
use anyhow::{Error, format_err, bail};
|
||||||
use serde_json::{json, Value};
|
use serde_json::Value;
|
||||||
|
|
||||||
use proxmox::sys::linux::procfs;
|
use proxmox::sys::linux::procfs;
|
||||||
|
|
||||||
|
@ -21,43 +21,7 @@ use crate::tools::cert::CertInfo;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
returns: {
|
returns: {
|
||||||
type: Object,
|
type: NodeStatus,
|
||||||
description: "Returns node memory, CPU and (root) disk usage",
|
|
||||||
properties: {
|
|
||||||
memory: {
|
|
||||||
type: Object,
|
|
||||||
description: "node memory usage counters",
|
|
||||||
properties: {
|
|
||||||
total: {
|
|
||||||
description: "total memory",
|
|
||||||
type: Integer,
|
|
||||||
},
|
|
||||||
used: {
|
|
||||||
description: "total memory",
|
|
||||||
type: Integer,
|
|
||||||
},
|
|
||||||
free: {
|
|
||||||
description: "free memory",
|
|
||||||
type: Integer,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cpu: {
|
|
||||||
type: Number,
|
|
||||||
description: "Total CPU usage since last query.",
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
info: {
|
|
||||||
type: Object,
|
|
||||||
description: "contains node information",
|
|
||||||
properties: {
|
|
||||||
fingerprint: {
|
|
||||||
description: "The SSL Fingerprint",
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
permission: &Permission::Privilege(&["system", "status"], PRIV_SYS_AUDIT, false),
|
permission: &Permission::Privilege(&["system", "status"], PRIV_SYS_AUDIT, false),
|
||||||
|
@ -68,32 +32,25 @@ fn get_status(
|
||||||
_param: Value,
|
_param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
_rpcenv: &mut dyn RpcEnvironment,
|
_rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<NodeStatus, Error> {
|
||||||
|
|
||||||
let meminfo: procfs::ProcFsMemInfo = procfs::read_meminfo()?;
|
let meminfo: procfs::ProcFsMemInfo = procfs::read_meminfo()?;
|
||||||
|
let memory = NodeMemoryCounters {
|
||||||
|
total: meminfo.memtotal,
|
||||||
|
used: meminfo.memused,
|
||||||
|
free: meminfo.memfree,
|
||||||
|
};
|
||||||
|
|
||||||
let kstat: procfs::ProcFsStat = procfs::read_proc_stat()?;
|
let kstat: procfs::ProcFsStat = procfs::read_proc_stat()?;
|
||||||
let disk_usage = crate::tools::disks::disk_usage(Path::new("/"))?;
|
let cpu = kstat.cpu;
|
||||||
|
|
||||||
// get fingerprint
|
Ok(NodeStatus {
|
||||||
let cert = CertInfo::new()?;
|
memory,
|
||||||
let fp = cert.fingerprint()?;
|
root: crate::tools::disks::disk_usage(Path::new("/"))?,
|
||||||
|
cpu,
|
||||||
Ok(json!({
|
info: NodeInformation {
|
||||||
"memory": {
|
fingerprint: CertInfo::new()?.fingerprint()?,
|
||||||
"total": meminfo.memtotal,
|
|
||||||
"used": meminfo.memused,
|
|
||||||
"free": meminfo.memfree,
|
|
||||||
},
|
},
|
||||||
"cpu": kstat.cpu,
|
})
|
||||||
"root": {
|
|
||||||
"total": disk_usage.total,
|
|
||||||
"used": disk_usage.used,
|
|
||||||
"free": disk_usage.avail,
|
|
||||||
},
|
|
||||||
"info": {
|
|
||||||
"fingerprint": fp,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
|
Loading…
Reference in New Issue