Service Status im Dashboard
Dieser Commit ist enthalten in:
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
from pathlib import Path
|
||||
from flask import Blueprint, render_template, request, redirect, session, url_for, flash, send_file, jsonify, current_app
|
||||
import requests
|
||||
|
||||
import config
|
||||
from auth.decorators import login_required
|
||||
@@ -16,6 +17,81 @@ from utils.export import create_excel_export, prepare_audit_export_data
|
||||
admin_bp = Blueprint('admin', __name__)
|
||||
|
||||
|
||||
def check_service_health():
|
||||
"""Check health status of critical services"""
|
||||
services = []
|
||||
|
||||
# License Server Health Check
|
||||
license_server = {
|
||||
'name': 'License Server',
|
||||
'status': 'unknown',
|
||||
'response_time': None,
|
||||
'icon': '🔐',
|
||||
'details': None
|
||||
}
|
||||
|
||||
try:
|
||||
start_time = datetime.now()
|
||||
response = requests.get('http://license-server:8443/health', timeout=2)
|
||||
response_time = (datetime.now() - start_time).total_seconds() * 1000
|
||||
|
||||
if response.status_code == 200:
|
||||
license_server['status'] = 'healthy'
|
||||
license_server['response_time'] = round(response_time, 1)
|
||||
license_server['details'] = 'Betriebsbereit'
|
||||
else:
|
||||
license_server['status'] = 'unhealthy'
|
||||
license_server['details'] = f'HTTP {response.status_code}'
|
||||
except requests.exceptions.Timeout:
|
||||
license_server['status'] = 'down'
|
||||
license_server['details'] = 'Timeout - Server antwortet nicht'
|
||||
except requests.exceptions.ConnectionError:
|
||||
license_server['status'] = 'down'
|
||||
license_server['details'] = 'Verbindung fehlgeschlagen'
|
||||
except Exception as e:
|
||||
license_server['status'] = 'down'
|
||||
license_server['details'] = f'Fehler: {str(e)}'
|
||||
|
||||
services.append(license_server)
|
||||
|
||||
# PostgreSQL Health Check
|
||||
postgresql = {
|
||||
'name': 'PostgreSQL',
|
||||
'status': 'unknown',
|
||||
'response_time': None,
|
||||
'icon': '🗄️',
|
||||
'details': None
|
||||
}
|
||||
|
||||
try:
|
||||
start_time = datetime.now()
|
||||
with get_db_connection() as conn:
|
||||
cur = conn.cursor()
|
||||
cur.execute('SELECT 1')
|
||||
cur.close()
|
||||
response_time = (datetime.now() - start_time).total_seconds() * 1000
|
||||
|
||||
postgresql['status'] = 'healthy'
|
||||
postgresql['response_time'] = round(response_time, 1)
|
||||
postgresql['details'] = 'Datenbankverbindung aktiv'
|
||||
except Exception as e:
|
||||
postgresql['status'] = 'down'
|
||||
postgresql['details'] = f'Verbindungsfehler: {str(e)}'
|
||||
|
||||
services.append(postgresql)
|
||||
|
||||
# Calculate overall health
|
||||
healthy_count = sum(1 for s in services if s['status'] == 'healthy')
|
||||
total_count = len(services)
|
||||
|
||||
return {
|
||||
'services': services,
|
||||
'healthy_count': healthy_count,
|
||||
'total_count': total_count,
|
||||
'overall_status': 'healthy' if healthy_count == total_count else ('partial' if healthy_count > 0 else 'down')
|
||||
}
|
||||
|
||||
|
||||
@admin_bp.route("/")
|
||||
@login_required
|
||||
def dashboard():
|
||||
@@ -258,6 +334,9 @@ def dashboard():
|
||||
license_distribution = []
|
||||
hourly_sessions = []
|
||||
|
||||
# Get service health status
|
||||
service_health = check_service_health()
|
||||
|
||||
return render_template('dashboard.html',
|
||||
stats=stats,
|
||||
top_licenses=top_licenses,
|
||||
@@ -265,6 +344,7 @@ def dashboard():
|
||||
license_distribution=license_distribution,
|
||||
hourly_sessions=hourly_sessions,
|
||||
resource_stats=resource_stats,
|
||||
service_health=service_health,
|
||||
username=session.get('username'))
|
||||
finally:
|
||||
cur.close()
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren