mirror of
https://github.com/m1ngsama/tracker.git
synced 2025-12-24 10:51:43 +00:00
Major improvements and features: - Integrate all monitoring modules (config, alert, logger, temperature) - Add comprehensive error handling throughout codebase - Fix data exporter directory creation issue - Improve process monitor CPU accuracy with proper intervals - Fix logger file handle management New features: - Alert system with configurable thresholds - Automatic logging to daily log files - Data export to JSON/CSV formats - Configuration management via config.json - Temperature monitoring support CI/CD: - Add GitHub Actions workflows for automated testing - Add release workflow for automatic package building - Multi-platform testing (Linux, macOS, Windows) - Python 3.8-3.12 compatibility testing Package distribution: - Add setup.py and pyproject.toml for PyPI distribution - Add MANIFEST.in for proper file inclusion - Add comprehensive CHANGELOG.md - Update README with full documentation Bug fixes: - Fix ResourceWarning in logger - Add ZombieProcess exception handling - Improve error handling in all metric collection methods
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""
|
|
Data export functionality
|
|
"""
|
|
|
|
import json
|
|
import csv
|
|
from datetime import datetime
|
|
|
|
|
|
class DataExporter:
|
|
def __init__(self, output_dir='exports'):
|
|
self.output_dir = output_dir
|
|
self._ensure_directory()
|
|
|
|
def _ensure_directory(self):
|
|
"""Ensure the output directory exists"""
|
|
import os
|
|
if not os.path.exists(self.output_dir):
|
|
os.makedirs(self.output_dir)
|
|
|
|
def export_to_json(self, data, filename=None):
|
|
"""Export data to JSON format"""
|
|
if filename is None:
|
|
filename = f"tracker_data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
|
|
|
filepath = f"{self.output_dir}/{filename}"
|
|
|
|
try:
|
|
with open(filepath, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
return filepath
|
|
except IOError as e:
|
|
raise IOError(f"Failed to export data to JSON: {e}")
|
|
|
|
def export_to_csv(self, data, filename=None):
|
|
"""Export data to CSV format"""
|
|
if filename is None:
|
|
filename = f"tracker_data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
|
|
|
filepath = f"{self.output_dir}/{filename}"
|
|
|
|
try:
|
|
if isinstance(data, list) and len(data) > 0:
|
|
keys = data[0].keys()
|
|
with open(filepath, 'w', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys)
|
|
writer.writeheader()
|
|
writer.writerows(data)
|
|
return filepath
|
|
except IOError as e:
|
|
raise IOError(f"Failed to export data to CSV: {e}")
|