rs_docker/
stats.rs

1#[derive(Serialize, Deserialize, Debug)]
2pub struct Stats {
3    pub read: String,
4    pub network: Network,
5    pub memory_stats: MemoryStats,
6    pub cpu_stats: CpuStats,
7    pub blkio_stats: BlkioStats,
8}
9
10#[derive(Serialize, Deserialize, Debug)]
11pub struct Network {
12    pub rx_dropped: u64,
13    pub rx_bytes: u64,
14    pub rx_errors: u64,
15    pub tx_packets: u64,
16    pub tx_dropped: u64,
17    pub rx_packets: u64,
18    pub tx_errors: u64,
19    pub tx_bytes: u64,
20}
21
22#[derive(Serialize, Deserialize, Debug)]
23pub struct MemoryStats {
24    pub max_usage: u64,
25    pub usage: u64,
26    pub failcnt: u64,
27    pub limit: u64,
28    pub stats: MemoryStat,
29}
30
31#[derive(Serialize, Deserialize, Debug)]
32pub struct MemoryStat {
33    pub total_pgmajfault: u64,
34    pub cache: u64,
35    pub mapped_file: u64,
36    pub total_inactive_file: u64,
37    pub pgpgout: u64,
38    pub rss: u64,
39    pub total_mapped_file: u64,
40    pub writeback: u64,
41    pub unevictable: u64,
42    pub pgpgin: u64,
43    pub total_unevictable: u64,
44    pub pgmajfault: u64,
45    pub total_rss: u64,
46    pub total_rss_huge: u64,
47    pub total_writeback: u64,
48    pub total_inactive_anon: u64,
49    pub rss_huge: u64,
50    pub hierarchical_memory_limit: u64,
51    pub hierarchical_memsw_limit: u64,
52    pub total_pgfault: u64,
53    pub total_active_file: u64,
54    pub active_anon: u64,
55    pub total_active_anon: u64,
56    pub total_pgpgout: u64,
57    pub total_cache: u64,
58    pub inactive_anon: u64,
59    pub active_file: u64,
60    pub pgfault: u64,
61    pub inactive_file: u64,
62    pub total_pgpgin: u64,
63    pub swap: u64,
64    pub total_swap: u64,
65}
66
67#[derive(Serialize, Deserialize, Debug)]
68pub struct CpuStats {
69    pub cpu_usage: CpuUsage,
70    pub system_cpu_usage: u64,
71    pub throttling_data: ThrottlingData,
72}
73
74#[derive(Serialize, Deserialize, Debug)]
75pub struct CpuUsage {
76    pub percpu_usage: Vec<u64>,
77    pub usage_in_usermode: u64,
78    pub total_usage: u64,
79    pub usage_in_kernelmode: u64,
80}
81
82#[derive(Serialize, Deserialize, Debug)]
83pub struct ThrottlingData {
84    pub periods: u64,
85    pub throttled_periods: u64,
86    pub throttled_time: u64,
87}
88
89#[derive(Serialize, Deserialize, Debug)]
90pub struct BlkioStats {
91    pub io_service_bytes_recursive: Vec<BlkioStat>,
92    pub io_serviced_recursive: Vec<BlkioStat>,
93    pub io_queue_recursive: Vec<BlkioStat>,
94    pub io_service_time_recursive: Vec<BlkioStat>,
95    pub io_wait_time_recursive: Vec<BlkioStat>,
96    pub io_merged_recursive: Vec<BlkioStat>,
97    pub io_time_recursive: Vec<BlkioStat>,
98    pub sectors_recursive: Vec<BlkioStat>,
99}
100
101#[derive(Serialize, Deserialize, Debug)]
102pub struct BlkioStat {
103    pub major: u64,
104    pub minor: u64,
105    pub op: String,
106    pub value: u64,
107}
108
109impl Clone for Stats {
110    fn clone(&self) -> Stats {
111        let stats = Stats {
112            read: self.read.clone(),
113            network: self.network.clone(),
114            memory_stats: self.memory_stats.clone(),
115            cpu_stats: self.cpu_stats.clone(),
116            blkio_stats: self.blkio_stats.clone(),
117        };
118        return stats;
119    }
120}
121
122impl Clone for Network {
123    fn clone(&self) -> Self {
124        let network = Network {
125            rx_dropped: self.rx_dropped,
126            rx_bytes: self.rx_bytes,
127            rx_errors: self.rx_errors,
128            tx_packets: self.tx_packets,
129            tx_dropped: self.tx_dropped,
130            rx_packets: self.rx_packets,
131            tx_errors: self.tx_errors,
132            tx_bytes: self.tx_bytes,
133        };
134        return network;
135    }
136}
137
138impl Clone for MemoryStats {
139    fn clone(&self) -> Self {
140        let memory_stats = MemoryStats {
141            max_usage: self.max_usage,
142            usage: self.usage,
143            failcnt: self.failcnt,
144            limit: self.limit,
145            stats: self.stats.clone(),
146        };
147        return memory_stats;
148    }
149}
150
151impl Clone for MemoryStat {
152    fn clone(&self) -> Self {
153        let memory_stat = MemoryStat {
154            total_pgmajfault: self.total_pgmajfault,
155            cache: self.cache,
156            mapped_file: self.mapped_file,
157            total_inactive_file: self.total_inactive_file,
158            pgpgout: self.pgpgout,
159            rss: self.rss,
160            total_mapped_file: self.total_mapped_file,
161            writeback: self.writeback,
162            unevictable: self.unevictable,
163            pgpgin: self.pgpgin,
164            total_unevictable: self.total_unevictable,
165            pgmajfault: self.pgmajfault,
166            total_rss: self.total_rss,
167            total_rss_huge: self.total_rss_huge,
168            total_writeback: self.total_writeback,
169            total_inactive_anon: self.total_inactive_anon,
170            rss_huge: self.rss_huge,
171            hierarchical_memory_limit: self.hierarchical_memory_limit,
172            hierarchical_memsw_limit: self.hierarchical_memsw_limit,
173            total_pgfault: self.total_pgfault,
174            total_active_file: self.total_active_file,
175            active_anon: self.active_anon,
176            total_active_anon: self.total_active_anon,
177            total_pgpgout: self.total_pgpgout,
178            total_cache: self.total_cache,
179            inactive_anon: self.inactive_anon,
180            active_file: self.active_file,
181            pgfault: self.pgfault,
182            inactive_file: self.inactive_file,
183            total_pgpgin: self.total_pgpgin,
184            swap: self.swap,
185            total_swap: self.total_swap,
186        };
187        return memory_stat;
188    }
189}
190
191impl Clone for CpuStats {
192    fn clone(&self) -> Self {
193        let cpu_stats = CpuStats {
194            cpu_usage: self.cpu_usage.clone(),
195            system_cpu_usage: self.system_cpu_usage,
196            throttling_data: self.throttling_data.clone(),
197        };
198        return cpu_stats;
199    }
200}
201
202impl Clone for CpuUsage {
203    fn clone(&self) -> Self {
204        let cpu_usage = CpuUsage {
205            percpu_usage: self.percpu_usage.clone(),
206            usage_in_usermode: self.usage_in_usermode,
207            total_usage: self.total_usage,
208            usage_in_kernelmode: self.usage_in_kernelmode,
209        };
210        return cpu_usage;
211    }
212}
213
214impl Clone for ThrottlingData {
215    fn clone(&self) -> Self {
216        let throttling_data = ThrottlingData {
217            periods: self.periods,
218            throttled_periods: self.throttled_periods,
219            throttled_time: self.throttled_time,
220        };
221        return throttling_data;
222    }
223}
224
225impl Clone for BlkioStats {
226    fn clone(&self) -> Self {
227        let blkio_stats = BlkioStats {
228            io_service_bytes_recursive: self.io_service_bytes_recursive.clone(),
229            io_serviced_recursive: self.io_serviced_recursive.clone(),
230            io_queue_recursive: self.io_queue_recursive.clone(),
231            io_service_time_recursive: self.io_service_time_recursive.clone(),
232            io_wait_time_recursive: self.io_wait_time_recursive.clone(),
233            io_merged_recursive: self.io_merged_recursive.clone(),
234            io_time_recursive: self.io_time_recursive.clone(),
235            sectors_recursive: self.sectors_recursive.clone(),
236        };
237        return blkio_stats;
238    }
239}
240
241impl Clone for BlkioStat {
242    fn clone(&self) -> Self {
243        let blkio_stat = BlkioStat {
244            major: self.major,
245            minor: self.minor,
246            op: self.op.clone(),
247            value: self.value,
248        };
249        return blkio_stat;
250    }
251}