summaryrefslogtreecommitdiffstats
path: root/src/app/data_harvester/cpu.rs
blob: 8f45e191e3f65d4c923ccc33951ba6b2dd0d8510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 mut cpu_vec = Vec::new();

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

	cpu_vec
}