about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2025-02-23 06:08:09 -0600
committergennyble <gen@nyble.dev>2025-02-23 06:08:09 -0600
commite60e9fae45915a4ca4457dfdc9794980e373b1f1 (patch)
tree6fb7fcf9787ecbddf384ead4e9b42d941ba04e36 /src
parentf5f103404857fb4f21cf71ac72fd5aa88baed95a (diff)
downloadawake-e60e9fae45915a4ca4457dfdc9794980e373b1f1.tar.gz
awake-e60e9fae45915a4ca4457dfdc9794980e373b1f1.zip
Conf key to turn off statistics
Diffstat (limited to 'src')
-rw-r--r--src/gatherer.rs19
-rwxr-xr-xsrc/main.rs11
2 files changed, 25 insertions, 5 deletions
diff --git a/src/gatherer.rs b/src/gatherer.rs
index b1fa416..9b2a80a 100644
--- a/src/gatherer.rs
+++ b/src/gatherer.rs
@@ -31,10 +31,29 @@ impl Gatherer {
 fn task(state: AwakeState) {
 	tracing::info!("starting gatherer thread");
 
+	if !state.do_statistics {
+		tracing::warn!("statistics disabled");
+		return;
+	}
+
 	// I just want a graph on first boot; don't care about divisions just yet
 	make_mem_graph(&state);
 	make_net_graph(&state);
 
+	// If we collected a point less than a minute ago, like after
+	// just being restarted, wait until it's been a minute
+	let last_meminfo = state.database.get_last_host_meminfo();
+	let since = OffsetDateTime::now_utc() - last_meminfo.stamp;
+	if since < time::Duration::minutes(1) {
+		let to_minute = time::Duration::minutes(1) - since;
+
+		tracing::info!(
+			"waiting for {}s to space a minute apart",
+			to_minute.whole_seconds()
+		);
+		std::thread::sleep(to_minute.try_into().unwrap());
+	}
+
 	let mut last_netinfo: Option<Netinfo> = None;
 
 	// this is a `let _` because otherwise the attribute was
diff --git a/src/main.rs b/src/main.rs
index b2ac1e9..6d0f27e 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,6 +52,7 @@ use crate::{
 
 #[derive(Clone)]
 pub struct AwakeState {
+	pub do_statistics: bool,
 	pub database: Arc<Database>,
 	pub cache_path: Utf8PathBuf,
 	pub netinfo_upper_bound: Arc<AtomicUsize>,
@@ -81,6 +82,10 @@ async fn main() {
 	let hostname = conf.child_owned("Hostname").unwrap();
 	let dbpath = conf.child_owned("Database").unwrap();
 	let cache = conf.child_owned("Cache").unwrap();
+	let statistics = match conf.child_value("Statistics") {
+		None | Some("true") | Some("yes") | Some("collect") => true,
+		_ => false,
+	};
 
 	let database = Database::new(dbpath.into());
 	database.create_tables();
@@ -88,6 +93,7 @@ async fn main() {
 	let fs = Filesystem::new(&webroot);
 
 	let state = AwakeState {
+		do_statistics: statistics,
 		database: Arc::new(database),
 		cache_path: cache.into(),
 		netinfo_upper_bound: Arc::new(AtomicUsize::new(256)),
@@ -101,13 +107,8 @@ async fn main() {
 	}
 
 	let mut gatherer = Gatherer::new(state.clone());
-
-	#[cfg(target_os = "linux")]
 	gatherer.start();
 
-	#[cfg(not(target_os = "linux"))]
-	tracing::warn!("compilation target was not linux; not collecing stat data");
-
 	let settings = Settings {
 		template_dir: Utf8PathBuf::from(webroot.join(templates))
 			.canonicalize_utf8()