Spaces:
Runtime error
Runtime error
| # visualize_uptime.py | |
| #!/usr/bin/env python3 | |
| """ | |
| Script to visualize server uptime from log files | |
| """ | |
| import logging | |
| from modules.visualizer import load_status_log, plot_uptime_trend, plot_uptime_summary, get_uptime_stats | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(levelname)s - %(message)s', | |
| handlers=[ | |
| logging.FileHandler('visualization.log'), | |
| logging.StreamHandler() | |
| ] | |
| ) | |
| def main(): | |
| """Main function to generate visualizations""" | |
| try: | |
| print("π Loading server status log...") | |
| df = load_status_log() | |
| print(f"β Loaded {len(df)} status records") | |
| # Get and display statistics | |
| stats = get_uptime_stats(df) | |
| print(f"\nπ Server Status Statistics:") | |
| print(f" Total Checks: {stats['total_checks']}") | |
| print(f" UP Checks: {stats['up_checks']}") | |
| print(f" DOWN Checks: {stats['down_checks']}") | |
| print(f" Uptime: {stats['uptime_pct']}%") | |
| print(f" Downtime: {stats['downtime_pct']}%") | |
| # Generate charts | |
| print("\nπ¨ Generating visualizations...") | |
| trend_chart = plot_uptime_trend(df) | |
| summary_chart = plot_uptime_summary(df) | |
| print(f"\nβ Visualizations complete!") | |
| print(f" Trend chart: {trend_chart}") | |
| print(f" Summary chart: {summary_chart}") | |
| except FileNotFoundError: | |
| print("β Log file not found. Run some queries first to generate status logs.") | |
| logging.warning("Server status log file not found") | |
| except Exception as e: | |
| print(f"β Error visualizing uptime: {e}") | |
| logging.error(f"Error in visualization script: {e}", exc_info=True) | |
| if __name__ == "__main__": | |
| main() |