myspace134v / modules /visualize_uptime.py
rdune71's picture
Updad
dcaf42a
raw
history blame
1.79 kB
# 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()