v0.25.5
This commit is contained in:
1 parent
1dea7f55c8
commit
c819f0a335
151 files changed
+7610
-4264
No files matched your search
@@ -14,7 +14,10 @@ pub(crate) fn augment(view: &mut View) {
|
||||
if let Ok(stat) = fs::read_to_string("/proc/stat") {
|
||||
view.logical_cpus = Some(
|
||||
stat.lines()
|
||||
.filter(|line| line.starts_with("cpu") && line.as_bytes().get(3).is_some_and(u8::is_ascii_digit))
|
||||
.filter(|line| {
|
||||
line.starts_with("cpu")
|
||||
&& line.as_bytes().get(3).is_some_and(u8::is_ascii_digit)
|
||||
})
|
||||
.count(),
|
||||
)
|
||||
.filter(|count| *count > 0);
|
||||
@@ -33,7 +36,8 @@ pub(crate) fn augment(view: &mut View) {
|
||||
view.process_rss_bytes = key_value(&status, "VmRSS").map(|n| n.saturating_mul(1024));
|
||||
view.process_rss_anon_bytes = key_value(&status, "RssAnon").map(|n| n.saturating_mul(1024));
|
||||
view.process_rss_file_bytes = key_value(&status, "RssFile").map(|n| n.saturating_mul(1024));
|
||||
view.process_rss_shmem_bytes = key_value(&status, "RssShmem").map(|n| n.saturating_mul(1024));
|
||||
view.process_rss_shmem_bytes =
|
||||
key_value(&status, "RssShmem").map(|n| n.saturating_mul(1024));
|
||||
view.process_data_bytes = key_value(&status, "VmData").map(|n| n.saturating_mul(1024));
|
||||
view.process_swap_bytes = key_value(&status, "VmSwap").map(|n| n.saturating_mul(1024));
|
||||
view.process_threads = key_value(&status, "Threads");
|
||||
|
||||
+21
-12
@@ -191,8 +191,9 @@ fn is_loopback_interface(name: &str) -> bool {
|
||||
if name == "lo" {
|
||||
return true;
|
||||
}
|
||||
name.strip_prefix("lo")
|
||||
.is_some_and(|suffix| !suffix.is_empty() && suffix.bytes().all(|byte| byte.is_ascii_digit()))
|
||||
name.strip_prefix("lo").is_some_and(|suffix| {
|
||||
!suffix.is_empty() && suffix.bytes().all(|byte| byte.is_ascii_digit())
|
||||
})
|
||||
}
|
||||
|
||||
fn normalize_network_interfaces<I>(interfaces: I) -> Vec<NetworkInterfaceView>
|
||||
@@ -290,9 +291,12 @@ fn merge_network_interfaces(
|
||||
// Both libraries expose cumulative byte counters. Merge by interface name
|
||||
// and keep the larger counter so a partial/zero reading from one backend
|
||||
// cannot hide a usable reading from the other.
|
||||
normalize_network_interfaces(primary.into_iter().chain(secondary).map(|item| {
|
||||
(item.name, item.rx_bytes, item.tx_bytes)
|
||||
}))
|
||||
normalize_network_interfaces(
|
||||
primary
|
||||
.into_iter()
|
||||
.chain(secondary)
|
||||
.map(|item| (item.name, item.rx_bytes, item.tx_bytes)),
|
||||
)
|
||||
}
|
||||
|
||||
fn collect_network(view: &mut View) {
|
||||
@@ -301,10 +305,8 @@ fn collect_network(view: &mut View) {
|
||||
// sysinfo has no native network backend. Combining both inventories also
|
||||
// avoids dropping an interface when either backend is only partially
|
||||
// available. No shell commands or per-platform network parser are used.
|
||||
let interfaces = merge_network_interfaces(
|
||||
collect_network_sysinfo(),
|
||||
collect_network_systemstat(),
|
||||
);
|
||||
let interfaces =
|
||||
merge_network_interfaces(collect_network_sysinfo(), collect_network_systemstat());
|
||||
if interfaces.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -340,7 +342,9 @@ fn collect_process(view: &mut View, counters: &mut Counters) {
|
||||
view.process_virtual_memory_bytes = metrics.virtual_memory_bytes;
|
||||
view.process_virtual_memory_max_bytes = metrics.virtual_memory_max_bytes;
|
||||
view.process_start_time_seconds = metrics.start_time_seconds;
|
||||
view.open_fds = metrics.open_fds.and_then(|value| usize::try_from(value).ok());
|
||||
view.open_fds = metrics
|
||||
.open_fds
|
||||
.and_then(|value| usize::try_from(value).ok());
|
||||
view.max_fds = metrics.max_fds;
|
||||
view.process_threads = metrics.threads;
|
||||
}
|
||||
@@ -393,12 +397,17 @@ pub(crate) fn sample(previous: Option<(View, Counters)>) -> (View, Counters) {
|
||||
|
||||
view.sampled_at_ms = now_ms();
|
||||
if let Some((previous_view, previous_counters)) = previous {
|
||||
let seconds = view.sampled_at_ms.saturating_sub(previous_view.sampled_at_ms) as f64 / 1000.0;
|
||||
let seconds = view
|
||||
.sampled_at_ms
|
||||
.saturating_sub(previous_view.sampled_at_ms) as f64
|
||||
/ 1000.0;
|
||||
if seconds > 0.0 {
|
||||
view.process_cpu_percent = counters
|
||||
.process_cpu_seconds
|
||||
.zip(previous_counters.process_cpu_seconds)
|
||||
.and_then(|(current, old)| (current >= old).then_some((current - old) * 100.0 / seconds));
|
||||
.and_then(|(current, old)| {
|
||||
(current >= old).then_some((current - old) * 100.0 / seconds)
|
||||
});
|
||||
}
|
||||
calculate_rates(&mut view, &previous_view);
|
||||
}
|
||||
|
||||
@@ -74,8 +74,14 @@ mod tests {
|
||||
calculate_rates(&mut current, &previous);
|
||||
assert_eq!(current.network_rx_bytes_per_second, Some(100.0));
|
||||
assert_eq!(current.network_tx_bytes_per_second, Some(200.0));
|
||||
assert_eq!(current.network_interfaces[0].rx_bytes_per_second, Some(100.0));
|
||||
assert_eq!(current.network_interfaces[0].tx_bytes_per_second, Some(200.0));
|
||||
assert_eq!(
|
||||
current.network_interfaces[0].rx_bytes_per_second,
|
||||
Some(100.0)
|
||||
);
|
||||
assert_eq!(
|
||||
current.network_interfaces[0].tx_bytes_per_second,
|
||||
Some(200.0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user