sync hostname

This commit is contained in:
Robin Appelman 2021-03-27 23:36:45 +01:00
commit 61261ca227
4 changed files with 26 additions and 5 deletions

18
Cargo.lock generated
View file

@ -694,6 +694,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hostname"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
dependencies = [
"libc",
"match_cfg",
"winapi",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.3" version = "0.2.3"
@ -845,6 +856,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "match_cfg"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]] [[package]]
name = "matches" name = "matches"
version = "0.1.8" version = "0.1.8"
@ -1040,6 +1057,7 @@ dependencies = [
"futures-lite", "futures-lite",
"futures-util", "futures-util",
"heim", "heim",
"hostname",
"iai", "iai",
"once_cell", "once_cell",
"parse-display", "parse-display",

View file

@ -16,6 +16,7 @@ futures-lite = "1"
parse-display = "0.4" parse-display = "0.4"
regex = { version = "1", default-features = false } regex = { version = "1", default-features = false }
once_cell = "1" once_cell = "1"
hostname = "0.3"
[dev-dependencies] [dev-dependencies]
iai = "0.1" iai = "0.1"

View file

@ -11,13 +11,13 @@ 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 (hostname, cpu, network, disks, disk_usage) = try_join! { let (cpu, network, disks, disk_usage) = try_join! {
hostname(),
cpu_time(), cpu_time(),
network_stats(), network_stats(),
disk_stats(), disk_stats(),
disk_usage(), disk_usage(),
}?; }?;
let hostname = hostname()?;
let memory = memory()?; let memory = memory()?;
let temperatures = temperatures()?; let temperatures = temperatures()?;
let pools = pools(); let pools = pools();

View file

@ -1,4 +1,4 @@
use color_eyre::Result; use color_eyre::{Report, Result};
use futures_util::future; use futures_util::future;
use futures_util::stream::{Stream, StreamExt}; use futures_util::stream::{Stream, StreamExt};
use heim::cpu::time; use heim::cpu::time;
@ -127,8 +127,10 @@ pub async fn network_stats() -> Result<impl Stream<Item = IOStats>> {
})) }))
} }
pub async fn hostname() -> Result<String> { pub fn hostname() -> Result<String> {
Ok(heim::host::platform().await?.hostname().to_string()) hostname::get()?
.into_string()
.map_err(|_| Report::msg("non utf8 hostname"))
} }
pub async fn disk_stats() -> Result<impl Stream<Item = IOStats>> { pub async fn disk_stats() -> Result<impl Stream<Item = IOStats>> {