refactor: use dynamic paths for config and log files
This commit is contained in:
+8
-6
@@ -14,12 +14,17 @@ import configparser
|
|||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
|
# --- CALCOLO PERCORSI DINAMICI ---
|
||||||
|
AGENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
LOG_FILE = os.path.join(AGENT_DIR, 'node_agent.log')
|
||||||
|
CONFIG_FILE = os.path.join(AGENT_DIR, 'node_config.json')
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# 0. LOGGING & HARDWARE CONFIGURATION
|
# 0. LOGGING & HARDWARE CONFIGURATION
|
||||||
# ==========================================
|
# ==========================================
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
handlers=[
|
handlers=[
|
||||||
RotatingFileHandler('/opt/node_agent.log', maxBytes=2000000, backupCount=3),
|
RotatingFileHandler(LOG_FILE, maxBytes=2000000, backupCount=3),
|
||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
],
|
],
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
@@ -38,7 +43,7 @@ except ImportError:
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
# 1. UNIFIED CONFIGURATION LOADING
|
# 1. UNIFIED CONFIGURATION LOADING
|
||||||
# ==========================================
|
# ==========================================
|
||||||
CONFIG_PATH = Path("/opt/node_config.json")
|
CONFIG_PATH = Path(CONFIG_FILE)
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
try:
|
try:
|
||||||
@@ -170,10 +175,7 @@ def get_system_status():
|
|||||||
"disk_usage_percent": psutil.disk_usage('/').percent,
|
"disk_usage_percent": psutil.disk_usage('/').percent,
|
||||||
"processes": {},
|
"processes": {},
|
||||||
"timestamp": time.strftime("%H:%M:%S"),
|
"timestamp": time.strftime("%H:%M:%S"),
|
||||||
"profiles": {
|
"profiles": { k: v.get('label', f'PROFILE {k}') for k, v in cfg.get('profiles', {}).items() }
|
||||||
"A": cfg.get('profiles', {}).get('A', {}).get('label', 'PROFILE A'),
|
|
||||||
"B": cfg.get('profiles', {}).get('B', {}).get('label', 'PROFILE B')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
proc_path = Path(cfg['paths'].get('process_list', ''))
|
proc_path = Path(cfg['paths'].get('process_list', ''))
|
||||||
if proc_path.exists():
|
if proc_path.exists():
|
||||||
|
|||||||
Reference in New Issue
Block a user