mirror of
https://github.com/m1ngsama/tracker.git
synced 2025-12-24 10:51:43 +00:00
Add configuration file support
This commit is contained in:
parent
6d21ad6594
commit
ffbe8173ea
2 changed files with 67 additions and 0 deletions
17
config.json
Normal file
17
config.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"update_interval": 5,
|
||||
"display": {
|
||||
"show_cpu": true,
|
||||
"show_memory": true,
|
||||
"show_disk": true,
|
||||
"show_network": true,
|
||||
"show_processes": true,
|
||||
"show_temperatures": true
|
||||
},
|
||||
"process_limit": 5,
|
||||
"alert_thresholds": {
|
||||
"cpu_percent": 80,
|
||||
"memory_percent": 85,
|
||||
"disk_percent": 90
|
||||
}
|
||||
}
|
||||
50
config_manager.py
Normal file
50
config_manager.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
Configuration management for tracker
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self, config_file='config.json'):
|
||||
self.config_file = config_file
|
||||
self.config = self.load_config()
|
||||
|
||||
def load_config(self):
|
||||
"""Load configuration from JSON file"""
|
||||
if os.path.exists(self.config_file):
|
||||
with open(self.config_file, 'r') as f:
|
||||
return json.load(f)
|
||||
return self.get_default_config()
|
||||
|
||||
def get_default_config(self):
|
||||
"""Return default configuration"""
|
||||
return {
|
||||
'update_interval': 5,
|
||||
'display': {
|
||||
'show_cpu': True,
|
||||
'show_memory': True,
|
||||
'show_disk': True,
|
||||
'show_network': True,
|
||||
'show_processes': True,
|
||||
'show_temperatures': True
|
||||
},
|
||||
'process_limit': 5,
|
||||
'alert_thresholds': {
|
||||
'cpu_percent': 80,
|
||||
'memory_percent': 85,
|
||||
'disk_percent': 90
|
||||
}
|
||||
}
|
||||
|
||||
def get(self, key, default=None):
|
||||
"""Get configuration value"""
|
||||
keys = key.split('.')
|
||||
value = self.config
|
||||
for k in keys:
|
||||
if isinstance(value, dict):
|
||||
value = value.get(k, default)
|
||||
else:
|
||||
return default
|
||||
return value
|
||||
Loading…
Reference in a new issue