update sysinfo to support stats on network storage

This commit is contained in:
jb-alvarado 2023-12-23 23:13:54 +01:00
parent 9912405e4e
commit 873776908e
5 changed files with 87 additions and 70 deletions

122
Cargo.lock generated
View File

@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -126,7 +126,7 @@ dependencies = [
"parse-size",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -239,7 +239,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -458,7 +458,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c"
dependencies = [
"concurrent-queue",
"event-listener 4.0.0",
"event-listener 4.0.1",
"event-listener-strategy",
"futures-core",
"pin-project-lite",
@ -547,7 +547,7 @@ version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c"
dependencies = [
"event-listener 4.0.0",
"event-listener 4.0.1",
"event-listener-strategy",
"pin-project-lite",
]
@ -581,19 +581,19 @@ dependencies = [
[[package]]
name = "async-task"
version = "4.5.0"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1"
checksum = "e1d90cd0b264dfdd8eb5bad0a2c217c1f88fa96a8573f40e7b12de23fb468f46"
[[package]]
name = "async-trait"
version = "0.1.74"
version = "0.1.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -852,7 +852,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -1031,7 +1031,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -1042,7 +1042,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
dependencies = [
"darling_core",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -1178,9 +1178,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "event-listener"
version = "4.0.0"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae"
checksum = "84f2cdcf274580f2d63697192d744727b3198894b1bf02923643bf59e2c26712"
dependencies = [
"concurrent-queue",
"parking",
@ -1193,7 +1193,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3"
dependencies = [
"event-listener 4.0.0",
"event-listener 4.0.1",
"pin-project-lite",
]
@ -1225,7 +1225,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "ffplayout"
version = "0.20.2"
version = "0.20.3"
dependencies = [
"chrono",
"clap",
@ -1247,7 +1247,7 @@ dependencies = [
[[package]]
name = "ffplayout-api"
version = "0.20.2"
version = "0.20.3"
dependencies = [
"actix-files",
"actix-multipart",
@ -1286,7 +1286,7 @@ dependencies = [
[[package]]
name = "ffplayout-lib"
version = "0.20.2"
version = "0.20.3"
dependencies = [
"chrono",
"crossbeam-channel",
@ -1497,7 +1497,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -1705,9 +1705,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "hyper"
version = "0.14.27"
version = "0.14.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
dependencies = [
"bytes",
"futures-channel",
@ -1720,7 +1720,7 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.4.10",
"socket2 0.5.5",
"tokio",
"tower-service",
"tracing",
@ -2443,9 +2443,9 @@ dependencies = [
[[package]]
name = "pkg-config"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a"
[[package]]
name = "polling"
@ -2491,9 +2491,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.70"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8"
dependencies = [
"unicode-ident",
]
@ -2507,7 +2507,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -2630,9 +2630,9 @@ checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca"
[[package]]
name = "reqwest"
version = "0.11.22"
version = "0.11.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41"
dependencies = [
"base64",
"bytes",
@ -2860,7 +2860,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -2897,9 +2897,9 @@ dependencies = [
[[package]]
name = "serde_yaml"
version = "0.9.27"
version = "0.9.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c"
checksum = "a15e0ef66bf939a7c890a0bf6d5a733c70202225f9888a89ed5c62298b019129"
dependencies = [
"indexmap",
"itoa",
@ -2930,7 +2930,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -3337,9 +3337,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.41"
version = "2.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8"
dependencies = [
"proc-macro2",
"quote",
@ -3348,9 +3348,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.29.11"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666"
checksum = "c68492e7268037de59ae153d7efb79546cf94a18a9548235420d3d8d2436b4b1"
dependencies = [
"cfg-if",
"core-foundation-sys",
@ -3358,7 +3358,7 @@ dependencies = [
"ntapi",
"once_cell",
"rayon",
"winapi",
"windows",
]
[[package]]
@ -3406,7 +3406,7 @@ dependencies = [
[[package]]
name = "tests"
version = "0.20.2"
version = "0.20.3"
dependencies = [
"chrono",
"crossbeam-channel",
@ -3446,14 +3446,14 @@ checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
name = "time"
version = "0.3.30"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e"
dependencies = [
"deranged",
"itoa",
@ -3473,9 +3473,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.15"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f"
dependencies = [
"time-core",
]
@ -3509,9 +3509,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.35.0"
version = "1.35.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c"
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
dependencies = [
"backtrace",
"bytes",
@ -3534,7 +3534,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -3598,7 +3598,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -3778,7 +3778,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
"wasm-bindgen-shared",
]
@ -3812,7 +3812,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3876,6 +3876,16 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
dependencies = [
"windows-core",
"windows-targets 0.48.5",
]
[[package]]
name = "windows-core"
version = "0.51.1"
@ -4029,22 +4039,22 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.7.31"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d"
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.31"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a"
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]

View File

@ -4,7 +4,7 @@ default-members = ["ffplayout-api", "ffplayout-engine", "tests"]
resolver = "2"
[workspace.package]
version = "0.20.2"
version = "0.20.3"
license = "GPL-3.0"
repository = "https://github.com/ffplayout/ffplayout"
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]

View File

@ -39,7 +39,7 @@ serde_json = "1.0"
serde_yaml = "0.9"
simplelog = { version = "0.12", features = ["paris"] }
static-files = "0.2"
sysinfo = "0.29"
sysinfo ={ version = "0.30", features = ["linux-netdevs"] }
sqlx = { version = "0.7", features = ["runtime-tokio", "sqlite"] }
tokio = { version = "1.29", features = ["full"] }

View File

@ -18,7 +18,7 @@ use clap::Parser;
use lazy_static::lazy_static;
use path_clean::PathClean;
use simplelog::*;
use sysinfo::{System, SystemExt};
use sysinfo::{Disks, Networks, System};
pub mod api;
pub mod db;
@ -35,6 +35,10 @@ include!(concat!(env!("OUT_DIR"), "/generated.rs"));
lazy_static! {
pub static ref ARGS: Args = Args::parse();
pub static ref DISKS: Arc<Mutex<Disks>> =
Arc::new(Mutex::new(Disks::new_with_refreshed_list()));
pub static ref NETWORKS: Arc<Mutex<Networks>> =
Arc::new(Mutex::new(Networks::new_with_refreshed_list()));
pub static ref SYS: Arc<Mutex<System>> = Arc::new(Mutex::new(System::new_all()));
}

View File

@ -2,9 +2,9 @@
use local_ip_address::list_afinet_netifas;
use serde::Serialize;
use sysinfo::{CpuExt, DiskExt, NetworkExt, SystemExt};
use sysinfo::System;
use crate::SYS;
use crate::{DISKS, NETWORKS, SYS};
use ffplayout_lib::utils::PlayoutConfig;
#[derive(Debug, Serialize)]
@ -69,7 +69,10 @@ pub struct SystemStat {
}
pub fn stat(config: PlayoutConfig) -> SystemStat {
let mut disks = DISKS.lock().unwrap();
let mut networks = NETWORKS.lock().unwrap();
let mut sys = SYS.lock().unwrap();
let network_interfaces = list_afinet_netifas().unwrap_or_default();
let mut usage = 0.0;
let mut interfaces = vec![];
@ -82,10 +85,10 @@ pub fn stat(config: PlayoutConfig) -> SystemStat {
interfaces.dedup_by(|a, b| a.0 == b.0);
sys.refresh_cpu();
sys.refresh_disks();
disks.refresh();
networks.refresh();
sys.refresh_cpu_usage();
sys.refresh_memory();
sys.refresh_networks();
let cores = sys.cpus().len() as f32;
@ -100,7 +103,7 @@ pub fn stat(config: PlayoutConfig) -> SystemStat {
let mut storage = Storage::default();
for disk in sys.disks() {
for disk in &*disks {
if disk.mount_point().to_string_lossy().len() > 1
&& config.storage.path.starts_with(disk.mount_point())
{
@ -110,7 +113,7 @@ pub fn stat(config: PlayoutConfig) -> SystemStat {
}
}
let load_avg = sys.load_average();
let load_avg = System::load_average();
let load = Load {
one: load_avg.one,
five: load_avg.five,
@ -125,7 +128,7 @@ pub fn stat(config: PlayoutConfig) -> SystemStat {
let mut network = Network::default();
for (interface_name, data) in sys.networks() {
for (interface_name, data) in &*networks {
if !interfaces.is_empty() && interface_name == interfaces[0].0 {
network.name = interface_name.clone();
network.current_in = data.received();
@ -142,9 +145,9 @@ pub fn stat(config: PlayoutConfig) -> SystemStat {
};
let system = MySystem {
name: sys.name(),
kernel: sys.kernel_version(),
version: sys.os_version(),
name: System::name(),
kernel: System::kernel_version(),
version: System::os_version(),
};
SystemStat {