mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 18:24:08 +02:00
sync network stats
This commit is contained in:
parent
f0a4482ec5
commit
f076776b50
2 changed files with 40 additions and 12 deletions
|
|
@ -11,8 +11,7 @@ use std::collections::HashSet;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
pub async fn get_metrics() -> Result<String> {
|
pub async fn get_metrics() -> Result<String> {
|
||||||
let (network, disks, disk_usage) = try_join! {
|
let (disks, disk_usage) = try_join! {
|
||||||
network_stats(),
|
|
||||||
disk_stats(),
|
disk_stats(),
|
||||||
disk_usage(),
|
disk_usage(),
|
||||||
}?;
|
}?;
|
||||||
|
|
@ -21,6 +20,7 @@ pub async fn get_metrics() -> Result<String> {
|
||||||
let memory = memory()?;
|
let memory = memory()?;
|
||||||
let temperatures = temperatures()?;
|
let temperatures = temperatures()?;
|
||||||
let pools = pools();
|
let pools = pools();
|
||||||
|
let network = network_stats()?;
|
||||||
pin_mut!(network);
|
pin_mut!(network);
|
||||||
pin_mut!(disks);
|
pin_mut!(disks);
|
||||||
pin_mut!(disk_usage);
|
pin_mut!(disk_usage);
|
||||||
|
|
@ -58,7 +58,7 @@ pub async fn get_metrics() -> Result<String> {
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
while let Some(network) = network.next().await {
|
while let Some(network) = network.next() {
|
||||||
let network: IOStats = network;
|
let network: IOStats = network;
|
||||||
if network.bytes_received > 0 || network.bytes_sent > 0 {
|
if network.bytes_received > 0 || network.bytes_sent > 0 {
|
||||||
writeln!(
|
writeln!(
|
||||||
|
|
|
||||||
|
|
@ -127,15 +127,43 @@ pub fn cpu_time() -> Result<u64> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn network_stats() -> Result<impl Stream<Item = IOStats>> {
|
pub fn network_stats() -> Result<impl Iterator<Item = IOStats>> {
|
||||||
let networks = heim::net::io_counters().await?;
|
let stat = BufReader::new(File::open("/proc/net/dev")?);
|
||||||
Ok(networks
|
Ok(stat
|
||||||
.filter_map(|network| future::ready(network.ok()))
|
.lines()
|
||||||
.filter(|network| future::ready(network.interface().starts_with("enp")))
|
.filter_map(Result::ok)
|
||||||
.map(|network| IOStats {
|
.filter(|line: &String| line.starts_with("enp"))
|
||||||
interface: network.interface().into(),
|
.filter_map(|line: String| {
|
||||||
bytes_sent: network.bytes_sent().get::<information::byte>(),
|
let mut parts = line.split_ascii_whitespace();
|
||||||
bytes_received: network.bytes_recv().get::<information::byte>(),
|
if let (
|
||||||
|
Some(interface),
|
||||||
|
Some(bytes_received),
|
||||||
|
_err,
|
||||||
|
_drop,
|
||||||
|
_fifo,
|
||||||
|
_frame,
|
||||||
|
_compressed,
|
||||||
|
_multicast,
|
||||||
|
Some(bytes_sent),
|
||||||
|
) = (
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
parts.next(),
|
||||||
|
) {
|
||||||
|
Some(IOStats {
|
||||||
|
interface: interface.trim_end_matches(':').into(),
|
||||||
|
bytes_sent: bytes_sent.parse().ok()?,
|
||||||
|
bytes_received: bytes_received.parse().ok()?,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue