update to sysinfo 0.30

This commit is contained in:
mbecker20
2024-01-06 17:26:44 -08:00
parent 02a313d70b
commit 1895ebcf25
5 changed files with 151 additions and 51 deletions

90
Cargo.lock generated
View File

@@ -1566,7 +1566,7 @@ dependencies = [
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows",
"windows 0.48.0",
]
[[package]]
@@ -2243,7 +2243,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
@@ -3106,9 +3106,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "sysinfo"
version = "0.29.11"
version = "0.30.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666"
checksum = "1fb4f3438c8f6389c864e61221cbc97e9bca98b4daf39a5beb7bea660f528bb2"
dependencies = [
"cfg-if",
"core-foundation-sys",
@@ -3116,7 +3116,7 @@ dependencies = [
"ntapi",
"once_cell",
"rayon",
"winapi",
"windows 0.52.0",
]
[[package]]
@@ -3858,7 +3858,26 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
name = "windows"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [
"windows-core",
"windows-targets 0.52.0",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.0",
]
[[package]]
@@ -3882,7 +3901,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
@@ -3900,6 +3919,21 @@ dependencies = [
"windows_x86_64_msvc 0.48.0",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [
"windows_aarch64_gnullvm 0.52.0",
"windows_aarch64_msvc 0.52.0",
"windows_i686_gnu 0.52.0",
"windows_i686_msvc 0.52.0",
"windows_x86_64_gnu 0.52.0",
"windows_x86_64_gnullvm 0.52.0",
"windows_x86_64_msvc 0.52.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
@@ -3912,6 +3946,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
@@ -3924,6 +3964,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
@@ -3936,6 +3982,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
@@ -3948,6 +4000,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
@@ -3960,6 +4018,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
@@ -3972,6 +4036,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
@@ -3984,6 +4054,12 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.4.6"

View File

@@ -59,7 +59,7 @@ derive_builder = "0.12.0"
typeshare = "1.0.1"
strum = "0.25.0"
strum_macros = "0.25.2"
sysinfo = "0.29.10"
sysinfo = "0.30.5"
async-trait = "0.1.73"
urlencoding = "2.1.3"
rand = "0.8.5"

View File

@@ -12,7 +12,7 @@ impl State {
.filter(|status| status.stats.is_some())
.map(|status| {
let BasicSystemStats {
system_load,
load_average,
cpu_perc,
cpu_freq_mhz,
mem_total_gb,
@@ -24,7 +24,7 @@ impl State {
SystemStatsRecord {
ts,
sid: status.id.clone(),
system_load,
load_average,
cpu_perc,
cpu_freq_mhz,
mem_total_gb,

View File

@@ -4,15 +4,12 @@ use async_timing_util::wait_until_timelength;
use monitor_types::entities::{
server::stats::{
AllSystemStats, BasicSystemStats, CpuUsage, DiskUsage,
NetworkUsage, SingleCpuUsage, SingleDiskUsage, SystemComponent,
SystemInformation, SystemNetwork, SystemProcess,
LoadAverage, NetworkUsage, SingleCpuUsage, SingleDiskUsage,
SystemComponent, SystemInformation, SystemNetwork, SystemProcess,
},
Timelength,
};
use sysinfo::{
ComponentExt, CpuExt, DiskExt, NetworkExt, PidExt, ProcessExt,
SystemExt,
};
use sysinfo::System;
use tokio::sync::RwLock;
pub type StatsClient = Arc<RwLock<InnerStatsClient>>;
@@ -20,7 +17,10 @@ pub type StatsClient = Arc<RwLock<InnerStatsClient>>;
pub struct InnerStatsClient {
pub info: SystemInformation,
pub stats: AllSystemStats,
sys: sysinfo::System,
system: sysinfo::System,
disks: sysinfo::Disks,
components: sysinfo::Components,
networks: sysinfo::Networks,
}
const BYTES_PER_GB: f64 = 1073741824.0;
@@ -29,14 +29,20 @@ const BYTES_PER_KB: f64 = 1024.0;
impl InnerStatsClient {
pub fn new(polling_rate: Timelength) -> StatsClient {
let sys = sysinfo::System::new_all();
let system = sysinfo::System::new_all();
let disks = sysinfo::Disks::new_with_refreshed_list();
let components = sysinfo::Components::new_with_refreshed_list();
let networks = sysinfo::Networks::new_with_refreshed_list();
let stats = AllSystemStats {
polling_rate,
..Default::default()
};
let client = InnerStatsClient {
info: get_system_information(&sys),
sys,
info: get_system_information(&system),
system,
disks,
components,
networks,
stats,
};
let client = Arc::new(RwLock::new(client));
@@ -68,18 +74,19 @@ impl InnerStatsClient {
}
fn refresh(&mut self) {
self.sys.refresh_cpu();
self.sys.refresh_memory();
self.sys.refresh_networks();
self.sys.refresh_disks();
self.sys.refresh_components();
self.sys.refresh_processes();
self.system.refresh_cpu();
self.system.refresh_memory();
self.system.refresh_processes();
self.networks.refresh();
self.components.refresh();
self.disks.refresh();
}
fn refresh_lists(&mut self) {
self.sys.refresh_networks_list();
self.sys.refresh_disks_list();
self.sys.refresh_components_list();
self.networks.refresh_list();
self.disks.refresh_list();
self.components.refresh_list();
}
fn get_all_stats(&self) -> AllSystemStats {
@@ -97,26 +104,31 @@ impl InnerStatsClient {
}
fn get_basic_system_stats(&self) -> BasicSystemStats {
let cpu = self.sys.global_cpu_info();
let cpu = self.system.global_cpu_info();
let disk = self.get_disk_usage();
let load_average = System::load_average();
BasicSystemStats {
system_load: self.sys.load_average().one,
load_average: LoadAverage {
one: load_average.one,
five: load_average.five,
fifteen: load_average.fifteen,
},
cpu_perc: cpu.cpu_usage(),
cpu_freq_mhz: cpu.frequency() as f64,
mem_used_gb: self.sys.used_memory() as f64 / BYTES_PER_GB,
mem_total_gb: self.sys.total_memory() as f64 / BYTES_PER_GB,
mem_used_gb: self.system.used_memory() as f64 / BYTES_PER_GB,
mem_total_gb: self.system.total_memory() as f64 / BYTES_PER_GB,
disk_used_gb: disk.used_gb,
disk_total_gb: disk.total_gb,
}
}
fn get_cpu_usage(&self) -> CpuUsage {
let cpu = self.sys.global_cpu_info();
let cpu = self.system.global_cpu_info();
CpuUsage {
cpu_perc: cpu.cpu_usage(),
cpu_freq_mhz: cpu.frequency() as f64,
cpus: self
.sys
.system
.cpus()
.iter()
.map(|cpu| SingleCpuUsage {
@@ -131,8 +143,8 @@ impl InnerStatsClient {
let mut free_gb = 0.0;
let mut total_gb = 0.0;
let disks = self
.sys
.disks()
.disks
.list()
.iter()
.map(|disk| {
let disk_total = disk.total_space() as f64 / BYTES_PER_GB;
@@ -149,7 +161,7 @@ impl InnerStatsClient {
let used_gb = total_gb - free_gb;
let mut read_bytes = 0;
let mut write_bytes = 0;
for process in self.sys.processes().values() {
for process in self.system.processes().values() {
let disk_usage = process.disk_usage();
read_bytes += disk_usage.read_bytes;
write_bytes += disk_usage.written_bytes;
@@ -167,9 +179,9 @@ impl InnerStatsClient {
let mut recieved_kb = 0.0;
let mut transmitted_kb = 0.0;
let networks = self
.sys
.networks()
.into_iter()
.networks
.list()
.iter()
.map(|(name, n)| {
let recv = n.received() as f64 / BYTES_PER_KB;
let trans = n.transmitted() as f64 / BYTES_PER_KB;
@@ -192,8 +204,8 @@ impl InnerStatsClient {
fn get_components(&self) -> Vec<SystemComponent> {
let mut comps: Vec<_> = self
.sys
.components()
.components
.list()
.iter()
.map(|c| SystemComponent {
label: c.label().to_string(),
@@ -226,7 +238,7 @@ impl InnerStatsClient {
fn get_processes(&self) -> Vec<SystemProcess> {
let mut procs: Vec<_> = self
.sys
.system
.processes()
.iter()
.map(|(pid, p)| {
@@ -234,7 +246,11 @@ impl InnerStatsClient {
SystemProcess {
pid: pid.as_u32(),
name: p.name().to_string(),
exe: p.exe().to_str().unwrap_or("").to_string(),
exe: p
.exe()
.map(|exe| exe.to_str().unwrap_or_default())
.unwrap_or_default()
.to_string(),
cmd: p.cmd().to_vec(),
start_time: (p.start_time() * 1000) as f64,
cpu_perc: p.cpu_usage(),
@@ -261,11 +277,11 @@ fn get_system_information(
) -> SystemInformation {
let cpu = sys.global_cpu_info();
SystemInformation {
name: sys.name(),
os: sys.long_os_version(),
kernel: sys.kernel_version(),
name: System::name(),
os: System::long_os_version(),
kernel: System::kernel_version(),
host_name: System::host_name(),
core_count: sys.physical_core_count().map(|c| c as u32),
host_name: sys.host_name(),
cpu_brand: cpu.brand().to_string(),
}
}

View File

@@ -18,7 +18,7 @@ pub struct SystemStatsRecord {
#[index]
pub sid: String,
// basic stats
pub system_load: f64,
pub load_average: LoadAverage,
pub cpu_perc: f32,
pub cpu_freq_mhz: f64,
pub mem_used_gb: f64,
@@ -57,7 +57,7 @@ pub struct AllSystemStats {
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct BasicSystemStats {
pub system_load: f64,
pub load_average: LoadAverage,
pub cpu_perc: f32,
pub cpu_freq_mhz: f64,
pub mem_used_gb: f64,
@@ -66,6 +66,14 @@ pub struct BasicSystemStats {
pub disk_total_gb: f64,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
pub struct LoadAverage {
pub one: f64,
pub five: f64,
pub fifteen: f64,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct CpuUsage {