2 use serde_json
::{json, Value}
;
4 use proxmox
::sys
::linux
::procfs
;
6 use proxmox
::api
::{api, ApiMethod, Router, RpcEnvironment, SubdirMap, Permission}
;
7 use proxmox
::list_subdirs_api_method
;
9 use crate::api2
::types
::*;
10 use crate::config
::acl
::PRIV_SYS_AUDIT
;
22 description
: "Returns node memory, CPU and (root) disk usage",
26 description
: "node memory usage counters",
29 description
: "total memory",
33 description
: "total memory",
37 description
: "free memory",
44 description
: "Total CPU usage since last query.",
50 permission
: &Permission
::Privilege(&[], PRIV_SYS_AUDIT
, false),
53 /// Read node memory, CPU and (root) disk usage
57 _rpcenv
: &mut dyn RpcEnvironment
,
58 ) -> Result
<Value
, Error
> {
60 let meminfo
: procfs
::ProcFsMemInfo
= procfs
::read_meminfo()?
;
61 let kstat
: procfs
::ProcFsStat
= procfs
::read_proc_stat()?
;
65 "total": meminfo
.memtotal
,
66 "used": meminfo
.memused
,
67 "free": meminfo
.memfree
,
73 pub const USAGE_ROUTER
: Router
= Router
::new()
74 .get(&API_METHOD_GET_USAGE
);
76 pub const SUBDIRS
: SubdirMap
= &[
77 ("usage", &USAGE_ROUTER
),
79 pub const ROUTER
: Router
= Router
::new()
80 .get(&list_subdirs_api_method
!(SUBDIRS
))