Formatting, add Default trait to Machine struct
This commit is contained in:
parent
bb44f85e42
commit
ca6515fad4
@ -15,18 +15,22 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sysinfo::{System, SystemExt, DiskExt};
|
use sysinfo::{DiskExt, System, SystemExt};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub available: u64
|
pub available: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
pub fn new(name: String, size: u64, available: u64) -> Self {
|
pub fn new(name: String, size: u64, available: u64) -> Self {
|
||||||
Self { name, size, available }
|
Self {
|
||||||
|
name,
|
||||||
|
size,
|
||||||
|
available,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn used(&self) -> u64 {
|
pub fn used(&self) -> u64 {
|
||||||
@ -64,8 +68,18 @@ impl Machine {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<Memory>>();
|
.collect::<Vec<Memory>>();
|
||||||
let ram = Memory::new("RAM".into(), sys.total_memory() * 1000, sys.available_memory() * 1000);
|
// Size of RAM and Swap is returned in KB, unlike the drives’
|
||||||
let swap = Memory::new("Swap".into(), sys.total_swap() * 1000, sys.free_swap() * 1000);
|
// size which is in byte
|
||||||
|
let ram = Memory::new(
|
||||||
|
"RAM".into(),
|
||||||
|
sys.total_memory() * 1000,
|
||||||
|
sys.available_memory() * 1000,
|
||||||
|
);
|
||||||
|
let swap = Memory::new(
|
||||||
|
"Swap".into(),
|
||||||
|
sys.total_swap() * 1000,
|
||||||
|
sys.free_swap() * 1000,
|
||||||
|
);
|
||||||
Self {
|
Self {
|
||||||
os: sys.name().unwrap(),
|
os: sys.name().unwrap(),
|
||||||
kernel: sys.kernel_version().unwrap(),
|
kernel: sys.kernel_version().unwrap(),
|
||||||
@ -73,7 +87,13 @@ impl Machine {
|
|||||||
uptime: sys.uptime(),
|
uptime: sys.uptime(),
|
||||||
ram,
|
ram,
|
||||||
swap,
|
swap,
|
||||||
disks
|
disks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Machine {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user