mirror of
https://github.com/m1ngsama/tracker.git
synced 2025-12-24 10:51:43 +00:00
feat: Add temperature monitoring and data export
- Implement TemperatureMonitor (platform-specific) - Create DataExporter for JSON/CSV export functionality - Add export_to_json() for JSON format output - Add export_to_csv() for CSV format output - Auto-generate timestamped filenames - Create exports directory automatically - Integrate temperature monitor into SystemMonitor - Add temperature display to stats output
This commit is contained in:
parent
4d87dccf62
commit
c6ffadc724
3 changed files with 77 additions and 0 deletions
53
src/exporter.rs
Normal file
53
src/exporter.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use serde::Serialize;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use anyhow::Result;
|
||||
use chrono::Local;
|
||||
|
||||
pub struct DataExporter {
|
||||
output_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl DataExporter {
|
||||
pub fn new(output_dir: &str) -> Self {
|
||||
let output_dir = PathBuf::from(output_dir);
|
||||
if !output_dir.exists() {
|
||||
fs::create_dir_all(&output_dir).ok();
|
||||
}
|
||||
DataExporter { output_dir }
|
||||
}
|
||||
|
||||
pub fn export_to_json<T: Serialize>(&self, data: &T, filename: Option<String>) -> Result<PathBuf> {
|
||||
let filename = filename.unwrap_or_else(|| {
|
||||
format!("tracker_data_{}.json", Local::now().format("%Y%m%d_%H%M%S"))
|
||||
});
|
||||
|
||||
let filepath = self.output_dir.join(filename);
|
||||
let json = serde_json::to_string_pretty(data)?;
|
||||
fs::write(&filepath, json)?;
|
||||
|
||||
Ok(filepath)
|
||||
}
|
||||
|
||||
pub fn export_to_csv<T: Serialize>(&self, data: &[T], filename: Option<String>) -> Result<PathBuf> {
|
||||
let filename = filename.unwrap_or_else(|| {
|
||||
format!("tracker_data_{}.csv", Local::now().format("%Y%m%d_%H%M%S"))
|
||||
});
|
||||
|
||||
let filepath = self.output_dir.join(filename);
|
||||
let mut wtr = csv::Writer::from_path(&filepath)?;
|
||||
|
||||
for record in data {
|
||||
wtr.serialize(record)?;
|
||||
}
|
||||
|
||||
wtr.flush()?;
|
||||
Ok(filepath)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DataExporter {
|
||||
fn default() -> Self {
|
||||
Self::new("exports")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::config::Config;
|
||||
use crate::process::ProcessMonitor;
|
||||
use crate::temperature::TemperatureMonitor;
|
||||
use crate::alert::AlertSystem;
|
||||
use crate::logger::TrackerLogger;
|
||||
use sysinfo::{System, Disks, Networks};
|
||||
|
|
@ -11,6 +12,7 @@ pub struct SystemMonitor {
|
|||
disks: Disks,
|
||||
networks: Networks,
|
||||
process_monitor: ProcessMonitor,
|
||||
temperature_monitor: TemperatureMonitor,
|
||||
alert_system: AlertSystem,
|
||||
logger: TrackerLogger,
|
||||
}
|
||||
|
|
@ -23,6 +25,7 @@ impl SystemMonitor {
|
|||
disks: Disks::new_with_refreshed_list(),
|
||||
networks: Networks::new_with_refreshed_list(),
|
||||
process_monitor: ProcessMonitor::new(),
|
||||
temperature_monitor: TemperatureMonitor::new(),
|
||||
alert_system: AlertSystem::new(config),
|
||||
logger: TrackerLogger::default(),
|
||||
}
|
||||
|
|
@ -149,6 +152,10 @@ impl SystemMonitor {
|
|||
if self.config.display.show_processes {
|
||||
self.process_monitor.display_processes(self.config.process_limit);
|
||||
}
|
||||
|
||||
if self.config.display.show_temperatures {
|
||||
self.temperature_monitor.display_temperatures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
src/temperature.rs
Normal file
17
src/temperature.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
pub struct TemperatureMonitor;
|
||||
|
||||
impl TemperatureMonitor {
|
||||
pub fn new() -> Self {
|
||||
TemperatureMonitor
|
||||
}
|
||||
|
||||
pub fn display_temperatures(&mut self) {
|
||||
println!("\nTemperature sensors not available on this system");
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TemperatureMonitor {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue