Add system health monitoring features with modular callbacks
- Introduced a new `system_health_constants.py` file to define thresholds and constants for system health metrics. - Refactored existing system health callbacks into modular components, enhancing maintainability and clarity. - Implemented dynamic loading of time range options in `charts.py`, improving flexibility in time range selection. - Added detailed documentation for new callback functions, ensuring clarity on their purpose and usage. - Enhanced error handling and logging practices across the new modules to ensure robust monitoring and debugging capabilities. These changes significantly improve the architecture and maintainability of the system health monitoring features, aligning with project standards for modularity and performance.
This commit is contained in:
@@ -4,6 +4,19 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_TIME_RANGE_OPTIONS = [
|
||||
{"label": "🕐 Last 1 Hour", "value": "1h"},
|
||||
{"label": "🕐 Last 4 Hours", "value": "4h"},
|
||||
{"label": "🕐 Last 6 Hours", "value": "6h"},
|
||||
{"label": "🕐 Last 12 Hours", "value": "12h"},
|
||||
{"label": "📅 Last 1 Day", "value": "1d"},
|
||||
{"label": "📅 Last 3 Days", "value": "3d"},
|
||||
{"label": "📅 Last 7 Days", "value": "7d"},
|
||||
{"label": "📅 Last 30 Days", "value": "30d"},
|
||||
{"label": "📅 Custom Range", "value": "custom"},
|
||||
{"label": "🔴 Real-time", "value": "realtime"}
|
||||
]
|
||||
|
||||
def load_time_range_options():
|
||||
"""Loads time range options from a JSON file.
|
||||
|
||||
@@ -21,43 +34,10 @@ def load_time_range_options():
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
logger.error(f"Time range options file not found at {file_path}. Using default.")
|
||||
return [
|
||||
{"label": "🕐 Last 1 Hour", "value": "1h"},
|
||||
{"label": "🕐 Last 4 Hours", "value": "4h"},
|
||||
{"label": "🕐 Last 6 Hours", "value": "6h"},
|
||||
{"label": "🕐 Last 12 Hours", "value": "12h"},
|
||||
{"label": "📅 Last 1 Day", "value": "1d"},
|
||||
{"label": "📅 Last 3 Days", "value": "3d"},
|
||||
{"label": "📅 Last 7 Days", "value": "7d"},
|
||||
{"label": "📅 Last 30 Days", "value": "30d"},
|
||||
{"label": "📅 Custom Range", "value": "custom"},
|
||||
{"label": "🔴 Real-time", "value": "realtime"}
|
||||
]
|
||||
return DEFAULT_TIME_RANGE_OPTIONS
|
||||
except json.JSONDecodeError:
|
||||
logger.error(f"Error decoding JSON from {file_path}. Using default.")
|
||||
return [
|
||||
{"label": "🕐 Last 1 Hour", "value": "1h"},
|
||||
{"label": "🕐 Last 4 Hours", "value": "4h"},
|
||||
{"label": "🕐 Last 6 Hours", "value": "6h"},
|
||||
{"label": "🕐 Last 12 Hours", "value": "12h"},
|
||||
{"label": "📅 Last 1 Day", "value": "1d"},
|
||||
{"label": "📅 Last 3 Days", "value": "3d"},
|
||||
{"label": "📅 Last 7 Days", "value": "7d"},
|
||||
{"label": "📅 Last 30 Days", "value": "30d"},
|
||||
{"label": "📅 Custom Range", "value": "custom"},
|
||||
{"label": "🔴 Real-time", "value": "realtime"}
|
||||
]
|
||||
return DEFAULT_TIME_RANGE_OPTIONS
|
||||
except Exception as e:
|
||||
logger.error(f"An unexpected error occurred while loading time range options: {e}. Using default.")
|
||||
return [
|
||||
{"label": "🕐 Last 1 Hour", "value": "1h"},
|
||||
{"label": "🕐 Last 4 Hours", "value": "4h"},
|
||||
{"label": "🕐 Last 6 Hours", "value": "6h"},
|
||||
{"label": "🕐 Last 12 Hours", "value": "12h"},
|
||||
{"label": "📅 Last 1 Day", "value": "1d"},
|
||||
{"label": "📅 Last 3 Days", "value": "3d"},
|
||||
{"label": "📅 Last 7 Days", "value": "7d"},
|
||||
{"label": "📅 Last 30 Days", "value": "30d"},
|
||||
{"label": "📅 Custom Range", "value": "custom"},
|
||||
{"label": "🔴 Real-time", "value": "realtime"}
|
||||
]
|
||||
return DEFAULT_TIME_RANGE_OPTIONS
|
||||
@@ -4,6 +4,19 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_TIMEFRAME_OPTIONS = [
|
||||
{'label': '1 Second', 'value': '1s'},
|
||||
{'label': '5 Seconds', 'value': '5s'},
|
||||
{'label': '15 Seconds', 'value': '15s'},
|
||||
{'label': '30 Seconds', 'value': '30s'},
|
||||
{'label': '1 Minute', 'value': '1m'},
|
||||
{'label': '5 Minutes', 'value': '5m'},
|
||||
{'label': '15 Minutes', 'value': '15m'},
|
||||
{'label': '1 Hour', 'value': '1h'},
|
||||
{'label': '4 Hours', 'value': '4h'},
|
||||
{'label': '1 Day', 'value': '1d'},
|
||||
]
|
||||
|
||||
def load_timeframe_options():
|
||||
"""Loads timeframe options from a JSON file.
|
||||
|
||||
@@ -21,43 +34,10 @@ def load_timeframe_options():
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
logger.error(f"Timeframe options file not found at {file_path}. Using default timeframes.")
|
||||
return [
|
||||
{'label': '1 Second', 'value': '1s'},
|
||||
{'label': '5 Seconds', 'value': '5s'},
|
||||
{'label': '15 Seconds', 'value': '15s'},
|
||||
{'label': '30 Seconds', 'value': '30s'},
|
||||
{'label': '1 Minute', 'value': '1m'},
|
||||
{'label': '5 Minutes', 'value': '5m'},
|
||||
{'label': '15 Minutes', 'value': '15m'},
|
||||
{'label': '1 Hour', 'value': '1h'},
|
||||
{'label': '4 Hours', 'value': '4h'},
|
||||
{'label': '1 Day', 'value': '1d'},
|
||||
]
|
||||
return DEFAULT_TIMEFRAME_OPTIONS
|
||||
except json.JSONDecodeError:
|
||||
logger.error(f"Error decoding JSON from {file_path}. Using default timeframes.")
|
||||
return [
|
||||
{'label': '1 Second', 'value': '1s'},
|
||||
{'label': '5 Seconds', 'value': '5s'},
|
||||
{'label': '15 Seconds', 'value': '15s'},
|
||||
{'label': '30 Seconds', 'value': '30s'},
|
||||
{'label': '1 Minute', 'value': '1m'},
|
||||
{'label': '5 Minutes', 'value': '5m'},
|
||||
{'label': '15 Minutes', 'value': '15m'},
|
||||
{'label': '1 Hour', 'value': '1h'},
|
||||
{'label': '4 Hours', 'value': '4h'},
|
||||
{'label': '1 Day', 'value': '1d'},
|
||||
]
|
||||
return DEFAULT_TIMEFRAME_OPTIONS
|
||||
except Exception as e:
|
||||
logger.error(f"An unexpected error occurred while loading timeframes: {e}. Using default timeframes.")
|
||||
return [
|
||||
{'label': '1 Second', 'value': '1s'},
|
||||
{'label': '5 Seconds', 'value': '5s'},
|
||||
{'label': '15 Seconds', 'value': '15s'},
|
||||
{'label': '30 Seconds', 'value': '30s'},
|
||||
{'label': '1 Minute', 'value': '1m'},
|
||||
{'label': '5 Minutes', 'value': '5m'},
|
||||
{'label': '15 Minutes', 'value': '15m'},
|
||||
{'label': '1 Hour', 'value': '1h'},
|
||||
{'label': '4 Hours', 'value': '4h'},
|
||||
{'label': '1 Day', 'value': '1d'},
|
||||
]
|
||||
return DEFAULT_TIMEFRAME_OPTIONS
|
||||
Reference in New Issue
Block a user