mirror of
				https://github.com/csehviktor/status-monitor.git
				synced 2025-08-08 18:06:14 +02:00 
			
		
		
		
	fix naming consistency
This commit is contained in:
		| @@ -1,13 +1,13 @@ | ||||
| use common::metrics::{Disk, Memory, Metrics, Network, SystemInfo, CPU}; | ||||
| use sysinfo::{Disks, Networks, System}; | ||||
|  | ||||
| use crate::cpu::CpuStatReader; | ||||
| use crate::cpu::CPUStatReader; | ||||
|  | ||||
| pub struct Collector { | ||||
|     sys: System, | ||||
|     disks: Disks, | ||||
|     networks: Networks, | ||||
|     cpu_reader: CpuStatReader, | ||||
|     cpu_reader: CPUStatReader, | ||||
| } | ||||
|  | ||||
| impl Collector { | ||||
| @@ -16,7 +16,7 @@ impl Collector { | ||||
|             sys: System::new_all(), | ||||
|             disks: Disks::new_with_refreshed_list(), | ||||
|             networks: Networks::new_with_refreshed_list(), | ||||
|             cpu_reader: CpuStatReader::new(), | ||||
|             cpu_reader: CPUStatReader::new(), | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| use std::collections::HashMap; | ||||
| use common::metrics::CpuBreakdown; | ||||
| use common::metrics::CPUBreakdown; | ||||
|  | ||||
| #[derive(Debug, Clone, Copy)] | ||||
| struct CpuValues { | ||||
| struct CPUValues { | ||||
|     pub user: u64, | ||||
|     pub nice: u64, | ||||
|     pub system: u64, | ||||
| @@ -15,23 +15,23 @@ struct CpuValues { | ||||
|     pub guest_nice: u64, | ||||
| } | ||||
|  | ||||
| impl CpuValues { | ||||
| impl CPUValues { | ||||
|     pub fn total(&self) -> u64 { | ||||
|         self.user + self.nice + self.system + self.idle + self.iowait + | ||||
|         self.irq + self.softirq + self.steal + self.guest + self.guest_nice | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub struct CpuStatReader { | ||||
|     previous_stats: HashMap<String, CpuValues>, | ||||
| pub struct CPUStatReader { | ||||
|     previous_stats: HashMap<String, CPUValues>, | ||||
| } | ||||
|  | ||||
| impl CpuStatReader { | ||||
| impl CPUStatReader { | ||||
|     pub fn new() -> Self { | ||||
|         Self { previous_stats: HashMap::new() } | ||||
|     } | ||||
|  | ||||
|     pub fn read_global_cpu_stats(&mut self) -> anyhow::Result<CpuBreakdown> { | ||||
|     pub fn read_global_cpu_stats(&mut self) -> anyhow::Result<CPUBreakdown> { | ||||
|         let content = std::fs::read_to_string("/proc/stat").unwrap(); | ||||
|  | ||||
|         let cpu_line = content | ||||
| @@ -42,7 +42,7 @@ impl CpuStatReader { | ||||
|         self.parse_cpu_line(cpu_line) | ||||
|     } | ||||
|  | ||||
|     fn parse_cpu_line(&mut self, line: &str) -> anyhow::Result<CpuBreakdown> { | ||||
|     fn parse_cpu_line(&mut self, line: &str) -> anyhow::Result<CPUBreakdown> { | ||||
|         let parts: Vec<&str> = line.split_whitespace().collect(); | ||||
|  | ||||
|         let cpu_name = parts[0].to_string(); | ||||
| @@ -51,7 +51,7 @@ impl CpuStatReader { | ||||
|             parts[num].parse().ok().unwrap() | ||||
|         }; | ||||
|  | ||||
|         let values = CpuValues { | ||||
|         let values = CPUValues { | ||||
|             user: parse(1), | ||||
|             nice: parse(2), | ||||
|             system: parse(3), | ||||
| @@ -72,21 +72,21 @@ impl CpuStatReader { | ||||
|         Ok(percentages) | ||||
|     } | ||||
|  | ||||
|     fn calculate_percentages(&self, current: &CpuValues, previous: Option<CpuValues>) -> CpuBreakdown { | ||||
|     fn calculate_percentages(&self, current: &CPUValues, previous: Option<CPUValues>) -> CPUBreakdown { | ||||
|         let Some(prev) = previous else { | ||||
|             return CpuBreakdown::default(); | ||||
|             return CPUBreakdown::default(); | ||||
|         }; | ||||
|  | ||||
|         let total_delta = current.total().saturating_sub(prev.total()) as f32; | ||||
|         if total_delta <= 0.0 { | ||||
|             return CpuBreakdown::default(); | ||||
|             return CPUBreakdown::default(); | ||||
|         } | ||||
|  | ||||
|         let calculate_pct = |current: u64, prev: u64| { | ||||
|             (current.saturating_sub(prev) as f32 / total_delta) * 100.0 | ||||
|         }; | ||||
|  | ||||
|         CpuBreakdown { | ||||
|         CPUBreakdown { | ||||
|             system: calculate_pct(current.system, prev.system), | ||||
|             user: calculate_pct(current.user, prev.user), | ||||
|             idle: calculate_pct(current.idle, prev.idle), | ||||
|   | ||||
| @@ -22,11 +22,11 @@ pub struct SystemInfo { | ||||
| pub struct CPU { | ||||
|     pub usage: f32, | ||||
|     pub threads: usize, | ||||
|     pub breakdown: CpuBreakdown, | ||||
|     pub breakdown: CPUBreakdown, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Serialize, Deserialize, Default)] | ||||
| pub struct CpuBreakdown { | ||||
| pub struct CPUBreakdown { | ||||
|     pub system: f32, | ||||
|     pub user: f32, | ||||
|     pub idle: f32, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user