mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 00:00:13 -08:00
feat: Implement comprehensive backup web application with Docker, systemd service, and Gunicorn support
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
|
||||
# Set environment
|
||||
os.environ['BACKUP_ROOT'] = '/home/acedanger/shell'
|
||||
@@ -13,9 +12,9 @@ def load_json_file(filepath):
|
||||
"""Safely load JSON file with error handling"""
|
||||
try:
|
||||
if os.path.exists(filepath):
|
||||
with open(filepath, 'r') as f:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
except Exception as e:
|
||||
except (OSError, json.JSONDecodeError, UnicodeDecodeError) as e:
|
||||
print(f"Error loading JSON file {filepath}: {e}")
|
||||
return None
|
||||
|
||||
@@ -25,35 +24,35 @@ def get_service_metrics(service_name):
|
||||
# Simple status file approach
|
||||
status_file = os.path.join(METRICS_DIR, f'{service_name}_status.json')
|
||||
|
||||
status = load_json_file(status_file)
|
||||
service_status = load_json_file(status_file)
|
||||
|
||||
return {
|
||||
'status': status,
|
||||
'last_run': status.get('end_time') if status else None,
|
||||
'current_status': status.get('status', 'unknown') if status else 'never_run',
|
||||
'files_processed': status.get('files_processed', 0) if status else 0,
|
||||
'total_size': status.get('total_size_bytes', 0) if status else 0,
|
||||
'duration': status.get('duration_seconds', 0) if status else 0
|
||||
'status': service_status,
|
||||
'last_run': service_status.get('end_time') if service_status else None,
|
||||
'current_status': service_status.get('status', 'unknown') if service_status else 'never_run',
|
||||
'files_processed': service_status.get('files_processed', 0) if service_status else 0,
|
||||
'total_size': service_status.get('total_size_bytes', 0) if service_status else 0,
|
||||
'duration': service_status.get('duration_seconds', 0) if service_status else 0
|
||||
}
|
||||
|
||||
|
||||
def get_consolidated_metrics():
|
||||
"""Get consolidated metrics across all services"""
|
||||
# With simplified approach, we consolidate by reading all status files
|
||||
services = {}
|
||||
all_services = {}
|
||||
|
||||
if os.path.exists(METRICS_DIR):
|
||||
for filename in os.listdir(METRICS_DIR):
|
||||
if filename.endswith('_status.json'):
|
||||
service_name = filename.replace('_status.json', '')
|
||||
status_file = os.path.join(METRICS_DIR, filename)
|
||||
status = load_json_file(status_file)
|
||||
if status:
|
||||
services[service_name] = status
|
||||
service_status = load_json_file(status_file)
|
||||
if service_status:
|
||||
all_services[service_name] = service_status
|
||||
|
||||
return {
|
||||
'services': services,
|
||||
'total_services': len(services),
|
||||
'services': all_services,
|
||||
'total_services': len(all_services),
|
||||
'last_updated': '2025-06-18T05:15:00-04:00'
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ if __name__ == "__main__":
|
||||
files = metrics['files_processed']
|
||||
duration = metrics['duration']
|
||||
print(f' {service}: {status} ({files} files, {duration}s)')
|
||||
except Exception as e:
|
||||
except (OSError, IOError, KeyError) as e:
|
||||
print(f' {service}: Error - {e}')
|
||||
|
||||
# Test consolidated metrics
|
||||
@@ -82,7 +81,7 @@ if __name__ == "__main__":
|
||||
for name, status in services.items():
|
||||
message = status.get('message', 'N/A')
|
||||
print(f' {name}: {status["status"]} - {message}')
|
||||
except Exception as e:
|
||||
except (OSError, IOError, KeyError) as e:
|
||||
print(f' Error: {e}')
|
||||
|
||||
print('\n✅ Web integration test completed successfully!')
|
||||
|
||||
Reference in New Issue
Block a user