-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_monitoring.py
More file actions
executable file
·140 lines (109 loc) · 4.07 KB
/
test_monitoring.py
File metadata and controls
executable file
·140 lines (109 loc) · 4.07 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
"""
Test monitoring and alerting system
"""
import os
import sys
sys.path.append(os.path.dirname(__file__))
from src.monitoring.alerting import AlertManager, ProcessingMonitor, AlertLevel
from src.monitoring.health_check import HealthChecker, HealthCheckAPI
import json
def test_alerting():
"""Test alerting functionality"""
print("🧪 Testing Alerting System")
print("=" * 50)
# Load config
config = {
'slack_webhook_url': os.getenv('SLACK_WEBHOOK_URL'),
'discord_webhook_url': os.getenv('DISCORD_WEBHOOK_URL')
}
if not config['slack_webhook_url'] and not config['discord_webhook_url']:
print("⚠️ No webhooks configured. Run setup_monitoring.py first.")
return
alert_manager = AlertManager(config)
# Test different alert levels
print("\n📤 Sending test alerts...")
# Info alert
alert_manager.send_alert(
title="System Started",
message="BlueDot Trading System monitoring is active",
level=AlertLevel.INFO,
details={'version': '1.0.0', 'environment': 'production'}
)
# Warning alert
alert_manager.send_alert(
title="High Memory Usage",
message="Memory usage exceeded 75% threshold",
level=AlertLevel.WARNING,
details={'current_usage': '78%', 'threshold': '75%'},
metrics={'memory_mb': 6234, 'available_mb': 1766}
)
# Error alert
alert_manager.send_alert(
title="Processing Failed",
message="Failed to process 5 files due to validation errors",
level=AlertLevel.ERROR,
details={'failed_files': 'AAPL, GOOGL, MSFT, AMZN, TSLA'},
metrics={'success_rate': '92%', 'failed_count': 5}
)
print("✅ Test alerts sent!")
def test_processing_monitor():
"""Test processing monitor"""
print("\n🧪 Testing Processing Monitor")
print("=" * 50)
config = {
'slack_webhook_url': os.getenv('SLACK_WEBHOOK_URL'),
'discord_webhook_url': os.getenv('DISCORD_WEBHOOK_URL')
}
alert_manager = AlertManager(config)
monitor = ProcessingMonitor(alert_manager)
# Simulate processing
print("\n📊 Simulating batch processing...")
# Start processing
monitor.start_processing(total_files=100, timeframe='daily', date='2024-08-02')
# Simulate file processing
for i in range(95):
monitor.file_processed(f'STOCK{i}', success=True)
# Simulate some failures
for i in range(5):
monitor.file_processed(f'FAIL{i}', success=False, error='Invalid JSON structure')
# End processing
monitor.end_processing()
print("✅ Processing simulation completed!")
def test_health_check():
"""Test health check system"""
print("\n🧪 Testing Health Check System")
print("=" * 50)
# Load config
with open('config/data_config.yaml', 'r') as f:
import yaml
config = yaml.safe_load(f)
health_checker = HealthChecker(config)
api = HealthCheckAPI(health_checker)
# Get health status
print("\n🏥 System Health Status:")
health = api.get_health_status()
print(f"Status: {health['status']}")
print(f"Issues: {len(health['issues'])}")
if health['issues']:
print("\n⚠️ Issues detected:")
for issue in health['issues']:
print(f" - [{issue['severity']}] {issue['type']}: {issue['message']}")
# Print metrics
print("\n📊 System Metrics:")
metrics = health['metrics']['system']
print(f" CPU: {metrics['cpu_percent']}%")
print(f" Memory: {metrics['memory_percent']}%")
print(f" Disk: {metrics['disk_usage_percent']}%")
# Simple status
simple = api.get_simple_status()
print(f"\n✅ Simple Status: {'Healthy' if simple['healthy'] else 'Unhealthy'}")
if __name__ == "__main__":
# Load environment variables
from dotenv import load_dotenv
load_dotenv()
# Run tests
test_alerting()
test_processing_monitor()
test_health_check()
print("\n✅ All monitoring tests completed!")