Skip to main content

Mountain/IPC/WindServiceHandlers/NativeHost/
OSStatistics.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `nativeHost:getOSStatistics`.
4//! Returns Electron-shaped `{ totalmem, freemem, loadavg }` snapshot.
5//! `loadavg` is the Unix triple; on Windows it's `[0,0,0]` by policy so the
6//! caller gets a well-formed array.
7
8use serde_json::{Value, json};
9
10pub async fn NativeOSStatistics() -> Result<Value, String> {
11	use sysinfo::System;
12
13	let mut Sys = System::new();
14	Sys.refresh_memory();
15
16	let TotalMem = Sys.total_memory();
17	let FreeMem = Sys.available_memory();
18
19	let LoadAvg = {
20		#[cfg(unix)]
21		{
22			let Load = System::load_average();
23			vec![Load.one, Load.five, Load.fifteen]
24		}
25		#[cfg(not(unix))]
26		{
27			vec![0.0, 0.0, 0.0]
28		}
29	};
30
31	Ok(json!({
32		"totalmem": TotalMem,
33		"freemem": FreeMem,
34		"loadavg": LoadAvg
35	}))
36}