summaryrefslogtreecommitdiffstats
path: root/src/app/data_harvester/cpu.rs
blob: c1f2dee23aec446d94f21841494720aa440b1a53 (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
use sysinfo::{ProcessorExt, System, SystemExt};

#[derive(Default, Debug, Clone)]
pub struct CPUData {
	pub cpu_name: String,
	pub cpu_usage: f64,
}

pub type CPUHarvest = Vec<CPUData>;

pub fn get_cpu_data_list(sys: &System) -> CPUHarvest {
	let cpu_data = sys.get_processors();
	let avg_cpu_usage = sys.get_global_processor_info().get_cpu_usage();
	let mut cpu_vec = vec![CPUData {
		cpu_name: "AVG".to_string(),
		cpu_usage: avg_cpu_usage as f64,
	}];

	for cpu in cpu_data {
		cpu_vec.push(CPUData {
			cpu_name: cpu.get_name().to_uppercase(),
			cpu_usage: f64::from(cpu.get_cpu_usage()),
		});
	}

	cpu_vec
}