xnode_manager_sdk/usage/
handlers.rs1use crate::{
2 usage::models::{CpuUsage, DiskUsage, MemoryUsage},
3 utils::{Empty, SessionGetInput, SessionGetOutput, session_get},
4};
5
6pub fn scope() -> String {
7 "/usage".to_string()
8}
9
10#[derive(Debug, Clone, PartialEq)]
11pub struct CpuPath {
12 pub scope: String,
13}
14pub type CpuInput<'a> = SessionGetInput<'a, CpuPath, Empty>;
15pub type CpuOutput = Vec<CpuUsage>;
16pub async fn cpu(input: CpuInput<'_>) -> SessionGetOutput<CpuOutput> {
17 session_get(input, scope(), |path| {
18 format!("/{scope}/cpu", scope = path.scope)
19 })
20 .await
21}
22
23#[derive(Debug, Clone, PartialEq)]
24pub struct MemoryPath {
25 pub scope: String,
26}
27pub type MemoryInput<'a> = SessionGetInput<'a, MemoryPath, Empty>;
28pub type MemoryOutput = MemoryUsage;
29pub async fn memory(input: MemoryInput<'_>) -> SessionGetOutput<MemoryOutput> {
30 session_get(input, scope(), |path| {
31 format!("/{scope}/memory", scope = path.scope)
32 })
33 .await
34}
35
36#[derive(Debug, Clone, PartialEq)]
37pub struct DiskPath {
38 pub scope: String,
39}
40pub type DiskInput<'a> = SessionGetInput<'a, DiskPath, Empty>;
41pub type DiskOutput = Vec<DiskUsage>;
42pub async fn disk(input: DiskInput<'_>) -> SessionGetOutput<DiskOutput> {
43 session_get(input, scope(), |path| {
44 format!("/{scope}/disk", scope = path.scope)
45 })
46 .await
47}