Skip to content

Commit

Permalink
chore: update sysinfo to 0.33.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jan 14, 2025
1 parent 189f0b7 commit f8fb8b2
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 27 deletions.
55 changes: 44 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ant-logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
rand = { version = "~0.8.5", features = ["small_rng"], optional = true }
serde = { version = "1.0.133", features = ["derive", "rc"] }
serde_json = { version = "1.0" }
sysinfo = { version = "0.30.8", default-features = false, optional = true }
sysinfo = { version = "0.33.1", default-features = false, optional = true }
thiserror = "1.0.23"
tokio = { version = "1.32.0", optional = true }
tracing = { version = "~0.1.26" }
Expand Down
18 changes: 12 additions & 6 deletions ant-logging/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use serde::Serialize;
use std::time::Duration;
use sysinfo::{self, Networks, Pid, System};
use sysinfo::{self, Networks, Pid, ProcessRefreshKind, ProcessesToUpdate, System};
use tracing::{debug, error};

const UPDATE_INTERVAL: Duration = Duration::from_secs(15);
Expand Down Expand Up @@ -70,10 +70,10 @@ pub async fn init_metrics(pid: u32) {
}
};

let cpu_stat = sys.global_cpu_info();
let system_cpu_usage_percent = sys.global_cpu_usage();
let metrics = Metrics {
physical_cpu_threads: sys.cpus().len(),
system_cpu_usage_percent: cpu_stat.cpu_usage(),
system_cpu_usage_percent,
process,
};
match serde_json::to_string(&metrics) {
Expand All @@ -87,8 +87,14 @@ pub async fn init_metrics(pid: u32) {

// Refreshes only the metrics that we interested in.
fn refresh_metrics(sys: &mut System, networks: &mut Networks, pid: Pid) {
sys.refresh_process(pid);
sys.refresh_memory();
sys.refresh_cpu();
networks.refresh();
sys.refresh_cpu_usage();
networks.refresh(true);

// To refresh only the specific process:
sys.refresh_processes_specifics(
ProcessesToUpdate::Some(&[pid]),
true,
ProcessRefreshKind::nothing().with_cpu().with_disk_usage().with_memory(),
);
}
2 changes: 1 addition & 1 deletion ant-networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ self_encryption = "~0.30.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
sha2 = "0.10"
strum = { version = "0.26.2", features = ["derive"] }
sysinfo = { version = "0.30.8", default-features = false, optional = true }
sysinfo = { version = "0.33.1", default-features = false, optional = true }
thiserror = "1.0.23"
tiny-keccak = { version = "~2.0.2", features = ["sha3"] }
tokio = { version = "1.32.0", features = [
Expand Down
8 changes: 6 additions & 2 deletions ant-networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use prometheus_client::{
metrics::family::Family,
metrics::{counter::Counter, gauge::Gauge},
};
use sysinfo::{Pid, ProcessRefreshKind, System};
use sysinfo::{Pid, ProcessRefreshKind, ProcessesToUpdate, System};
use tokio::time::Duration;

const UPDATE_INTERVAL: Duration = Duration::from_secs(15);
Expand Down Expand Up @@ -251,7 +251,11 @@ impl NetworkMetricsRecorder {

tokio::spawn(async move {
loop {
system.refresh_process_specifics(pid, process_refresh_kind);
system.refresh_processes_specifics(
ProcessesToUpdate::Some(&[pid]),
true,
process_refresh_kind,
);
if let (Some(process), Some(core_count)) =
(system.process(pid), physical_core_count)
{
Expand Down
2 changes: 1 addition & 1 deletion ant-node-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ semver = "1.0.20"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
service-manager = "0.7.0"
sysinfo = "0.30.12"
sysinfo = "0.33.1"
thiserror = "1.0.23"
tokio = { version = "1.26", features = ["full"] }
tracing = { version = "~0.1.26" }
Expand Down
2 changes: 1 addition & 1 deletion ant-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rayon = "1.8.0"
self_encryption = "~0.30.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
strum = { version = "0.26.2", features = ["derive"] }
sysinfo = { version = "0.30.8", default-features = false }
sysinfo = { version = "0.33.1", default-features = false }
thiserror = "1.0.23"
tokio = { version = "1.32.0", features = [
"io-util",
Expand Down
8 changes: 6 additions & 2 deletions ant-node/src/bin/antnode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::{
process::Command,
time::Duration,
};
use sysinfo::{self, Pid, ProcessRefreshKind, System};
use sysinfo::{self, Pid, ProcessRefreshKind, ProcessesToUpdate, System};
use tokio::{
runtime::Runtime,
sync::{broadcast::error::RecvError, mpsc},
Expand Down Expand Up @@ -443,7 +443,11 @@ You can check your reward balance by running:
tokio::time::sleep(initial_delay).await;

loop {
system.refresh_process_specifics(pid, process_refresh_kind);
system.refresh_processes_specifics(
ProcessesToUpdate::Some(&[pid]),
true,
process_refresh_kind,
);
if let (Some(process), Some(core_count)) = (system.process(pid), physical_core_count) {
// divide by core_count to get value between 0-100
let cpu_usage =
Expand Down
2 changes: 1 addition & 1 deletion ant-service-management/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
semver = "1.0.20"
service-manager = "0.7.0"
sysinfo = "0.30.12"
sysinfo = "0.33.1"
thiserror = "1.0.23"
tokio = { version = "1.32.0", features = ["time"] }
tonic = { version = "0.6.2" }
Expand Down
2 changes: 1 addition & 1 deletion node-launchpad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ serde_json = "1.0.107"
signal-hook = "0.3.17"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.1", features = ["derive"] }
sysinfo = "0.30.12"
sysinfo = "0.33.1"
throbber-widgets-tui = "0.8.0"
tokio = { version = "1.32.0", features = ["full"] }
tokio-util = "0.7.9"
Expand Down

0 comments on commit f8fb8b2

Please sign in to comment.