Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
OSStatistics.rs

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