Skip to main content

rsys/os/linux/
os_impl_ext.rs

1use super::{cpu::*, kernel_version, mem::*, misc::*, net::*, ps::*, storage::*, Linux};
2use crate::Result;
3
4/// Trait extending Rsys functionality with linux specific api
5pub trait OsImplExt {
6    //
7    // storage
8    //
9
10    /// Parses a StorageDevice object from system. If the provided name
11    /// doesn't start with `sd` returns an error.
12    fn stat_block_device(&self, name: &str) -> Result<StorageDevice>;
13
14    /// Parses a DeviceMapper object from system. If the provided name
15    /// doesn't start with `dm` returns an error.
16    fn stat_device_mapper(&self, name: &str) -> Result<DeviceMapper>;
17
18    /// Parses a ScsiCdrom object from system. If the provided name
19    /// doesn't start with `sr` returns an error.
20    fn stat_scsi_cdrom(&self, name: &str) -> Result<ScsiCdrom>;
21
22    /// Parses a MultipleDeviceStorage object from system. If the provided name
23    /// doesn't start with `md` returns an error.
24    fn stat_multiple_device_storage(&self, name: &str) -> Result<MultipleDeviceStorage>;
25
26    /// Returns block size of device in bytes
27    fn block_size(&self, name: &str) -> Result<i64>;
28
29    //
30    // memory
31    //
32
33    /// Returns detailed information about memory
34    fn memory(&self) -> Result<Memory>;
35
36    //
37    // ps
38    //
39
40    /// Returns detailed Process information parsed from /proc/[pid]/stat
41    fn stat_process(&self, pid: i32) -> Result<Process>;
42
43    /// Returns a list of pids read from /proc
44    fn pids(&self) -> Result<Vec<i32>>;
45
46    /// Returns all processes currently seen in /proc parsed as Processes
47    fn processes(&self) -> Result<Processes>;
48
49    //
50    // other
51    //
52
53    /// Returns kernel version of host os.
54    fn kernel_version(&self) -> Result<String>;
55
56    /// Returns MountPoints read from /proc/mounts
57    fn mounts(&self) -> Result<MountPoints>;
58
59    //
60    // cpu
61    //
62
63    /// Returns virtual Cores of host cpu
64    fn cores(&self) -> Result<Cores>;
65
66    /// Returns a Processor object containing gathered information about host cpu
67    fn processor(&self) -> Result<Processor>;
68
69    //
70    // net
71    //
72
73    /// Returns network interfaces on host os
74    fn ifaces(&self) -> Result<Interfaces>;
75}
76
77impl OsImplExt for Linux {
78    //
79    // storage
80    //
81
82    fn stat_block_device(&self, name: &str) -> Result<StorageDevice> {
83        stat_block_device(name)
84    }
85
86    fn stat_device_mapper(&self, name: &str) -> Result<DeviceMapper> {
87        stat_device_mapper(name)
88    }
89
90    fn stat_scsi_cdrom(&self, name: &str) -> Result<ScsiCdrom> {
91        stat_scsi_cdrom(name)
92    }
93
94    fn stat_multiple_device_storage(&self, name: &str) -> Result<MultipleDeviceStorage> {
95        stat_multiple_device_storage(name)
96    }
97
98    fn block_size(&self, name: &str) -> Result<i64> {
99        block_size(name)
100    }
101
102    //
103    // mem
104    //
105
106    fn memory(&self) -> Result<Memory> {
107        memory()
108    }
109
110    //
111    // ps
112    //
113
114    fn stat_process(&self, pid: i32) -> Result<Process> {
115        stat_process(pid)
116    }
117
118    fn pids(&self) -> Result<Vec<i32>> {
119        pids()
120    }
121
122    fn processes(&self) -> Result<Processes> {
123        processes()
124    }
125
126    //
127    // other
128    //
129
130    fn kernel_version(&self) -> Result<String> {
131        kernel_version()
132    }
133
134    fn mounts(&self) -> Result<MountPoints> {
135        mounts()
136    }
137
138    //
139    // cpu
140    //
141
142    fn cores(&self) -> Result<Cores> {
143        cores()
144    }
145
146    fn processor(&self) -> Result<Processor> {
147        processor()
148    }
149
150    //
151    // net
152    //
153
154    fn ifaces(&self) -> Result<Interfaces> {
155        ifaces()
156    }
157}