about summary refs log tree commit diff
path: root/splorm/src/templated/features.rs
blob: 06b6336a566745ae5a18f857a63160f347c13614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! optional template features
//!
//! *(`Sternum`)* is currently broken which is not letting me put doc comments
//! on the [`Feature`].
//!
//! [`Feature::SystemStats`] fill variables used for including system statistics
//! obtained from gatherer (see [`GathererConnector`])

use bempline::Document;
use gny::sternum::Sternum;

use crate::state::SplormState;

#[derive(Sternum, Debug, PartialEq)]
pub enum Feature {
	SystemStats,
}

/// apply system stat template variables
pub async fn apply_system_stats(doc: &mut Document, state: &SplormState) {
	let bounds = {
		let mut lock = state.gatherer_thread().await;
		match lock.regular_graphs().await {
			Err(_) => return,
			Ok(graphs) => graphs.bounds,
		}
	};

	doc.set("stats.mem.total", bounds.mem_upper / 1000);
	doc.set("stats.mem.usage", bounds.mem_current / 1000);
	doc.set("stats.net.max_bound", bounds.net_upper);
	doc.set("stats.cpu.max_bound", bounds.cpu_upper);
}