start gathering stats using new rrd module

This commit is contained in:
Dietmar Maurer 2020-05-23 10:43:08 +02:00
parent 6359dc891a
commit eaeda365e0
2 changed files with 40 additions and 2 deletions

View File

@ -34,6 +34,8 @@ async fn run() -> Result<(), Error> {
config::update_self_signed_cert(false)?;
proxmox_backup::rrd::create_rrdb_dir()?;
if let Err(err) = generate_auth_key() {
bail!("unable to generate auth key - {}", err);
}
@ -46,7 +48,7 @@ async fn run() -> Result<(), Error> {
let config = server::ApiConfig::new(
buildcfg::JS_DIR, &proxmox_backup::api2::ROUTER, RpcEnvironmentType::PRIVILEGED)?;
let rest_server = RestServer::new(config);
// http server future:
@ -86,6 +88,6 @@ async fn run() -> Result<(), Error> {
proxmox_backup::server::last_worker_future().await?;
log::info!("done - exit server");
Ok(())
}

View File

@ -108,6 +108,7 @@ async fn run() -> Result<(), Error> {
}
start_task_scheduler();
start_stat_generator();
server.await?;
log::info!("server shutting down, waiting for active workers to complete");
@ -117,6 +118,13 @@ async fn run() -> Result<(), Error> {
Ok(())
}
fn start_stat_generator() {
let abort_future = server::shutdown_future();
let future = Box::pin(run_stat_generator());
let task = futures::future::select(future, abort_future);
tokio::spawn(task.map(|_| ()));
}
fn start_task_scheduler() {
let abort_future = server::shutdown_future();
let future = Box::pin(run_task_scheduler());
@ -579,3 +587,31 @@ async fn schedule_datastore_sync_jobs() {
}
}
}
async fn run_stat_generator() {
loop {
let delay_target = Instant::now() + Duration::from_secs(10);
generate_host_stats().await;
tokio::time::delay_until(tokio::time::Instant::from_std(delay_target)).await;
}
}
async fn generate_host_stats() {
use proxmox::sys::linux::procfs::read_proc_stat;
use proxmox_backup::rrd;
match read_proc_stat() {
Ok(stat) => {
if let Err(err) = rrd::update_value("host/cpu", stat.cpu) {
eprintln!("rrd::update_value 'host/cpu' failed - {}", err);
}
}
Err(err) => {
eprintln!("read_proc_stat failed - {}", err);
}
}
}