- Introduced a new modular structure for the dashboard, enhancing maintainability and scalability. - Created main application entry point in `app_new.py`, integrating all components and callbacks. - Developed layout modules for market data, bot management, performance analytics, and system health in the `layouts` directory. - Implemented callback modules for navigation, charts, indicators, and system health in the `callbacks` directory. - Established reusable UI components in the `components` directory, including chart controls and indicator modals. - Enhanced documentation to reflect the new modular structure and provide clear usage guidelines. - Ensured all components are under 300-400 lines for better readability and maintainability.
96 lines
3.9 KiB
Python
96 lines
3.9 KiB
Python
"""
|
|
System health callbacks for the dashboard.
|
|
"""
|
|
|
|
from dash import Output, Input, html
|
|
from datetime import datetime
|
|
from utils.logger import get_logger
|
|
from database.connection import DatabaseManager
|
|
from components.charts import create_data_status_indicator, check_data_availability
|
|
|
|
logger = get_logger("system_health_callbacks")
|
|
|
|
|
|
def register_system_health_callbacks(app):
|
|
"""Register system health callbacks."""
|
|
|
|
@app.callback(
|
|
Output('database-status', 'children'),
|
|
Input('interval-component', 'n_intervals')
|
|
)
|
|
def update_database_status(n_intervals):
|
|
"""Update database connection status."""
|
|
try:
|
|
db_manager = DatabaseManager()
|
|
|
|
# Test database connection
|
|
with db_manager.get_session() as session:
|
|
# Simple query to test connection
|
|
result = session.execute("SELECT 1").fetchone()
|
|
|
|
if result:
|
|
return html.Div([
|
|
html.Span("🟢 Connected", style={'color': '#27ae60', 'font-weight': 'bold'}),
|
|
html.P(f"Last checked: {datetime.now().strftime('%H:%M:%S')}",
|
|
style={'margin': '5px 0', 'color': '#7f8c8d'})
|
|
])
|
|
else:
|
|
return html.Div([
|
|
html.Span("🔴 Connection Error", style={'color': '#e74c3c', 'font-weight': 'bold'})
|
|
])
|
|
|
|
except Exception as e:
|
|
logger.error(f"Database status check failed: {e}")
|
|
return html.Div([
|
|
html.Span("🔴 Connection Failed", style={'color': '#e74c3c', 'font-weight': 'bold'}),
|
|
html.P(f"Error: {str(e)}", style={'color': '#7f8c8d', 'font-size': '12px'})
|
|
])
|
|
|
|
@app.callback(
|
|
Output('collection-status', 'children'),
|
|
[Input('symbol-dropdown', 'value'),
|
|
Input('timeframe-dropdown', 'value'),
|
|
Input('interval-component', 'n_intervals')]
|
|
)
|
|
def update_data_status(symbol, timeframe, n_intervals):
|
|
"""Update data collection status."""
|
|
try:
|
|
# Check real data availability
|
|
status = check_data_availability(symbol, timeframe)
|
|
|
|
return html.Div([
|
|
html.Div(
|
|
create_data_status_indicator(symbol, timeframe),
|
|
style={'margin': '10px 0'}
|
|
),
|
|
html.P(f"Checking data for {symbol} {timeframe}",
|
|
style={'color': '#7f8c8d', 'margin': '5px 0', 'font-style': 'italic'})
|
|
], style={'background-color': '#f8f9fa', 'padding': '15px', 'border-radius': '5px'})
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error updating data status: {e}")
|
|
return html.Div([
|
|
html.Span("🔴 Status Check Failed", style={'color': '#e74c3c', 'font-weight': 'bold'}),
|
|
html.P(f"Error: {str(e)}", style={'color': '#7f8c8d', 'margin': '5px 0'})
|
|
])
|
|
|
|
@app.callback(
|
|
Output('redis-status', 'children'),
|
|
Input('interval-component', 'n_intervals')
|
|
)
|
|
def update_redis_status(n_intervals):
|
|
"""Update Redis connection status."""
|
|
try:
|
|
# TODO: Implement Redis status check when Redis is integrated
|
|
return html.Div([
|
|
html.Span("🟡 Not Configured", style={'color': '#f39c12', 'font-weight': 'bold'}),
|
|
html.P("Redis integration pending", style={'color': '#7f8c8d', 'margin': '5px 0'})
|
|
])
|
|
except Exception as e:
|
|
logger.error(f"Redis status check failed: {e}")
|
|
return html.Div([
|
|
html.Span("🔴 Check Failed", style={'color': '#e74c3c', 'font-weight': 'bold'}),
|
|
html.P(f"Error: {str(e)}", style={'color': '#7f8c8d', 'font-size': '12px'})
|
|
])
|
|
|
|
logger.info("System health callbacks registered successfully") |