File size: 1,789 Bytes
dcaf42a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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()