System metrics and process inspection library.
Dependencies
moon add Milky2018/sysinfolet system = @sysinfo.System::new_all()
println("supported=\{@sysinfo.is_supported_system}")
println("total_memory=\{system.total_memory()}")
println("used_memory=\{system.used_memory()}")
println("cpu_usage=\{system.global_cpu_usage()}")
println("process_count=\{system.processes().size()}")let system = @sysinfo.System::new_all()
system.refresh_cpu_usage()
sleep(220)
system.refresh_cpu_usage()
let usage = system.global_cpu_usage()pub(all) struct CGroupLimits {
total_memory : UInt64
free_memory : UInt64
free_swap : UInt64
}pub(all) struct Component {
temperature : Double?
max : Double?
critical : Double?
label : String
id : String?
}pub(all) struct Cpu {
name : String
vendor_id : String
brand : String
frequency : UInt64
cpu_usage : Double
}pub(all) struct CpuRefreshKind {
cpu_usage : Bool
frequency : Bool
}impl Eq for CpuRefreshKindimpl Show for CpuRefreshKindtype CpuSnapshottype DiskIoSnapshotpub(all) enum DiskKind {
HDD
SSD
Unknown(String)
}pub(all) struct DiskRefreshKind {
kind : Bool
storage : Bool
io_usage : Bool
}impl Eq for DiskRefreshKindimpl Show for DiskRefreshKindpub(all) struct DiskUsage {
total_read_bytes : UInt64
read_bytes : UInt64
total_written_bytes : UInt64
written_bytes : UInt64
}fn Disks::refresh_specifics(self : Disks, remove_not_listed_disks : Bool, refreshes : DiskRefreshKind) -> Unitpub(all) struct Gid {
value : Int
}pub(all) struct IpNetwork {
raw : String
}pub(all) enum KillError {
Unsupported
NotFound
PermissionDenied
Timeout
WaitFailed
Unknown(String)
}pub(all) struct LoadAvg {
one : Double
five : Double
fifteen : Double
}pub(all) struct MacAddr {
raw : String
}type MacosDiskInfopub(all) struct MemoryRefreshKind {
ram : Bool
swap : Bool
}impl Eq for MemoryRefreshKindimpl Show for MemoryRefreshKindtype MountEntrypub(all) struct NetworkData {
received : UInt64
total_received : UInt64
transmitted : UInt64
total_transmitted : UInt64
packets_received : UInt64
total_packets_received : UInt64
packets_transmitted : UInt64
total_packets_transmitted : UInt64
errors_on_received : UInt64
total_errors_on_received : UInt64
errors_on_transmitted : UInt64
total_errors_on_transmitted : UInt64
mac_address : MacAddr
ip_networks : Array[IpNetwork]
mtu : UInt64
}impl Eq for NetworkDataimpl Show for NetworkDatapub(all) struct Pid {
value : Int
}pub(all) struct Process {
pid : Pid
parent : Pid?
name : String
cmd : Array[String]
environ : Array[String]
exe : String?
cwd : String?
root : String?
memory : UInt64
virtual_memory : UInt64
status : ProcessStatus
start_time : UInt64
run_time : UInt64
cpu_usage : Double
accumulated_cpu_time : UInt64
disk_usage : DiskUsage
user_id : Uid?
effective_user_id : Uid?
group_id : Gid?
effective_group_id : Gid?
session_id : Pid?
tasks : Array[Pid]?
thread_kind : ThreadKind?
open_files : Int?
open_files_limit : Int?
}pub(all) struct ProcessRefreshKind {
cpu : Bool
disk_usage : Bool
memory : Bool
user : UpdateKind
cwd : UpdateKind
root : UpdateKind
environ : UpdateKind
cmd : UpdateKind
exe : UpdateKind
tasks : Bool
}impl Eq for ProcessRefreshKindimpl Show for ProcessRefreshKindfn ProcessRefreshKind::with_environ(self : ProcessRefreshKind, kind : UpdateKind) -> ProcessRefreshKindfn ProcessRefreshKind::with_root(self : ProcessRefreshKind, kind : UpdateKind) -> ProcessRefreshKindfn ProcessRefreshKind::with_user(self : ProcessRefreshKind, kind : UpdateKind) -> ProcessRefreshKindpub(all) enum ProcessStatus {
Dead
Idle
LockBlocked
Parked
Run
Sleep
Stop
Suspended
Tracing
UninterruptibleDiskSleep
Unknown(Int)
Wakekill
Waking
Zombie
}impl Eq for ProcessesToUpdateimpl Show for ProcessesToUpdatepub(all) struct RefreshKind {
processes : ProcessRefreshKind?
memory : MemoryRefreshKind?
cpu : CpuRefreshKind?
}impl Eq for RefreshKindimpl Show for RefreshKindpub(all) enum Signal {
Abort
Alarm
Bus
Child
Continue
FloatingPointException
Hangup
IO
IOT
Illegal
Interrupt
Kill
Pipe
Poll
Power
Profiling
Quit
Segv
Stop
Sys
TSTP
TTIN
TTOU
Term
Trap
Urgent
User1
User2
VirtualAlarm
Winch
XCPU
XFSZ
}pub(all) struct System {
processes_data : Map[Pid, Process]
cpus_data : Array[Cpu]
total_memory_data : UInt64
free_memory_data : UInt64
available_memory_data : UInt64
used_memory_data : UInt64
total_swap_data : UInt64
free_swap_data : UInt64
used_swap_data : UInt64
cgroup_limits_data : CGroupLimits?
last_cpu_refresh_ms : UInt64
prev_cpu_snapshots : Array[CpuSnapshot]
prev_global_cpu_snapshot : CpuSnapshot?
prev_proc_cpu_total : Map[Pid, UInt64]
prev_proc_system_total : UInt64
}fn System::refresh_processes(self : System, processes_to_update : ProcessesToUpdate, remove_dead_processes : Bool) -> Intfn System::refresh_processes_specifics(self : System, processes_to_update : ProcessesToUpdate, remove_dead_processes : Bool, refresh_kind : ProcessRefreshKind) -> Intpub(all) enum ThreadKind {
Kernel
Userland
}pub(all) struct Uid {
value : Int
}pub(all) enum UpdateKind {
Never
Always
OnlyIfNotSet
}System metrics and process inspection library.
Dependencies