mirror of
https://github.com/m1ngsama/tracker.git
synced 2025-12-24 10:51:43 +00:00
feat: Implement configuration management module
- Create Config struct with serde support for JSON parsing - Define DisplayConfig for UI toggle options - Define AlertThresholds for monitoring alerts - Implement Default trait for sensible defaults - Add load() method to read config from file - Support same config format as Python version for compatibility
This commit is contained in:
parent
66a2f517c3
commit
ee427dddba
1 changed files with 59 additions and 0 deletions
59
src/config.rs
Normal file
59
src/config.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub update_interval: u64,
|
||||||
|
pub display: DisplayConfig,
|
||||||
|
pub process_limit: usize,
|
||||||
|
pub alert_thresholds: AlertThresholds,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct DisplayConfig {
|
||||||
|
pub show_cpu: bool,
|
||||||
|
pub show_memory: bool,
|
||||||
|
pub show_disk: bool,
|
||||||
|
pub show_network: bool,
|
||||||
|
pub show_processes: bool,
|
||||||
|
pub show_temperatures: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AlertThresholds {
|
||||||
|
pub cpu_percent: f32,
|
||||||
|
pub memory_percent: f32,
|
||||||
|
pub disk_percent: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Config {
|
||||||
|
update_interval: 5,
|
||||||
|
display: DisplayConfig {
|
||||||
|
show_cpu: true,
|
||||||
|
show_memory: true,
|
||||||
|
show_disk: true,
|
||||||
|
show_network: true,
|
||||||
|
show_processes: true,
|
||||||
|
show_temperatures: true,
|
||||||
|
},
|
||||||
|
process_limit: 5,
|
||||||
|
alert_thresholds: AlertThresholds {
|
||||||
|
cpu_percent: 80.0,
|
||||||
|
memory_percent: 85.0,
|
||||||
|
disk_percent: 90.0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||||
|
let contents = fs::read_to_string(path)?;
|
||||||
|
let config: Config = serde_json::from_str(&contents)?;
|
||||||
|
Ok(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue