1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
@File: model/balloon_stats.rs
@Author: Mugen_Cyaegha (Xue Haonan)
*/
use crate::utils::Json;
use serde::{Deserialize, Serialize};

/// Describes the balloon device statistics.
/// 
/// This structure represents the return value requested
/// by `GET /balloon/statistics`, which describes detailed
/// information of the balloon device.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BalloonStatistics {
    /// Target number of pages the device aims to hold.
    /// Required: true
    #[serde(rename = "target_pages")]
    pub target_pages: u64,

    /// Actual number of pages the device is holding.
    /// Required: true
    #[serde(rename = "actual_pages")]
    pub actual_pages: u64,

    /// Target amount of memory (in MiB) the device aims to hold.
    /// Required: true
    #[serde(rename = "target_mib")]
    pub target_mib: u64,

    /// Actual amount of memory (in MiB) the device is holding.
    /// Required: true
    #[serde(rename = "actual_mib")]
    pub actual_mib: u64,

    /// The amount of memory that has been swapped in (in bytes).
    #[serde(rename = "swap_in", skip_serializing_if = "Option::is_none")]
    pub swap_in: Option<u64>,

    /// The amount of memory that has been swapped out to disk (in bytes).
    #[serde(rename = "swap_out", skip_serializing_if = "Option::is_none")]
    pub swap_out: Option<u64>,

    /// The number of major page faults that have occurred.
    #[serde(rename = "major_faults", skip_serializing_if = "Option::is_none")]
    pub major_faults: Option<u64>,

    /// The number of minor page faults that have occurred.
    #[serde(rename = "minor_faults", skip_serializing_if = "Option::is_none")]
    pub minor_faults: Option<u64>,

    /// The amount of memory not being used for any purpose (in bytes).
    #[serde(rename = "free_memory", skip_serializing_if = "Option::is_none")]
    pub free_memory: Option<u64>,

    /// The total amount of memory available (in bytes).
    #[serde(rename = "total_memory", skip_serializing_if = "Option::is_none")]
    pub total_memory: Option<u64>,

    /// An estimate of how much memory is available (in bytes) for starting new applications
    /// without pushing the system to swap;
    #[serde(rename = "available_memory", skip_serializing_if = "Option::is_none")]
    pub available_memory: Option<u64>,

    /// The amount of memory, in bytes, that can be quickly reclaimed without additional I/O.
    /// Typically these pages are used for caching files from disk.
    #[serde(rename = "disk_caches", skip_serializing_if = "Option::is_none")]
    pub disk_caches: Option<u64>,

    /// The number of successful hugetlb page allocations in the guest.
    #[serde(rename = "hugetlb_allocations", skip_serializing_if = "Option::is_none")]
    pub hugetlb_allocations: Option<u64>,

    /// The number of failed hugetlb page allocations in the guest.
    #[serde(rename = "hugetlb_failures", skip_serializing_if = "Option::is_none")]
    pub hugetlb_failures: Option<u64>,
}

impl<'a> Json<'a> for BalloonStatistics {
    type Item = BalloonStatistics;
}