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
15	Sys.refresh_memory();
16
17	let TotalMem = Sys.total_memory();
18
19	let FreeMem = Sys.available_memory();
20
21	let LoadAvg = {
22		#[cfg(unix)]
23		{
24			let Load = System::load_average();
25
26			vec![Load.one, Load.five, Load.fifteen]
27		}
28
29		#[cfg(not(unix))]
30		{
31			vec![0.0, 0.0, 0.0]
32		}
33	};
34
35	Ok(json!({
36		"totalmem": TotalMem,
37		"freemem": FreeMem,
38		"loadavg": LoadAvg
39	}))
40}