🚧 wip: collecting CPU time used.
parent
96106e68fc
commit
1e5aa528c9
|
@ -97,7 +97,7 @@ async fn main () -> Result <(), anyhow::Error> {
|
||||||
config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ())
|
config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ())
|
||||||
);
|
);
|
||||||
|
|
||||||
let metrics_gauges = Arc::new (ArcSwap::from_pointee (None));
|
let metrics_gauges = Arc::new (ArcSwap::default ());
|
||||||
|
|
||||||
let gauge_writer = Arc::clone (&metrics_gauges);
|
let gauge_writer = Arc::clone (&metrics_gauges);
|
||||||
|
|
||||||
|
|
|
@ -33,24 +33,57 @@ pub struct Startup {
|
||||||
pub startup_utc: DateTime <Utc>,
|
pub startup_utc: DateTime <Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gauges are things we instananeously measure on a fixed interval.
|
||||||
|
// They are not read back and accumulated like counters.
|
||||||
|
|
||||||
#[derive (Debug, serde::Serialize)]
|
#[derive (Debug, serde::Serialize)]
|
||||||
pub struct Gauges {
|
pub struct Gauges {
|
||||||
pub utc: DateTime <Utc>,
|
pub utc: DateTime <Utc>,
|
||||||
pub rss_mib: u64,
|
pub rss_mib: u64,
|
||||||
|
|
||||||
|
// What's the difference?
|
||||||
|
pub cpu_time_user: f64,
|
||||||
|
pub cpu_time_system: f64,
|
||||||
|
|
||||||
|
#[serde (skip)]
|
||||||
|
pub cpu_usage: heim::process::CpuUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gauges {
|
impl Gauges {
|
||||||
pub async fn new () -> Result <Self, super::FileServerError> {
|
pub async fn new () -> Result <Self, super::FileServerError> {
|
||||||
|
use tokio::join;
|
||||||
use heim::process;
|
use heim::process;
|
||||||
use uom::si::information::mebibyte;
|
use uom::si::{
|
||||||
|
information::mebibyte,
|
||||||
|
ratio,
|
||||||
|
time::second,
|
||||||
|
};
|
||||||
|
|
||||||
let our_process = process::current ().await?;
|
let our_process = process::current ().await?;
|
||||||
|
|
||||||
|
let cpu_time = our_process.cpu_time ();
|
||||||
|
let cpu_usage = our_process.cpu_usage ();
|
||||||
|
|
||||||
|
let (cpu_time, cpu_usage) = join! (
|
||||||
|
cpu_time,
|
||||||
|
cpu_usage,
|
||||||
|
);
|
||||||
|
|
||||||
|
let cpu_time = cpu_time?;
|
||||||
|
|
||||||
|
let cpu_time_user = cpu_time.user ().get::<second> ();
|
||||||
|
let cpu_time_system = cpu_time.system ().get::<second> ();
|
||||||
|
let cpu_usage = cpu_usage?;
|
||||||
|
|
||||||
let mem = our_process.memory ().await?;
|
let mem = our_process.memory ().await?;
|
||||||
let rss_mib = mem.rss ().get::<mebibyte> ();
|
let rss_mib = mem.rss ().get::<mebibyte> ();
|
||||||
|
|
||||||
let x = Gauges {
|
let x = Gauges {
|
||||||
utc: Utc::now (),
|
utc: Utc::now (),
|
||||||
rss_mib,
|
rss_mib,
|
||||||
|
cpu_time_user,
|
||||||
|
cpu_time_system,
|
||||||
|
cpu_usage,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug! ("metric gauges: {:?}", x);
|
debug! ("metric gauges: {:?}", x);
|
||||||
|
|
|
@ -201,7 +201,7 @@ pub async fn run_server (
|
||||||
let handlebars = file_server::load_templates (&asset_root)?;
|
let handlebars = file_server::load_templates (&asset_root)?;
|
||||||
|
|
||||||
let metrics_startup = file_server::metrics::Startup::new (config_file.name);
|
let metrics_startup = file_server::metrics::Startup::new (config_file.name);
|
||||||
let metrics_gauges = Arc::new (ArcSwap::from_pointee (None));
|
let metrics_gauges = Arc::new (ArcSwap::default ());
|
||||||
|
|
||||||
let state = Arc::new (State {
|
let state = Arc::new (State {
|
||||||
file_server: file_server::State {
|
file_server: file_server::State {
|
||||||
|
|
Loading…
Reference in New Issue