-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring_client.py
31 lines (25 loc) · 1.01 KB
/
monitoring_client.py
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
import time
from notification import notification
class MonitoringClient:
def __init__(self, error_threshold=5, error_interval=300):
self.error_count = 0
self.last_error_time = None
self.error_threshold = error_threshold
self.error_interval = error_interval
def record_success(self):
self.error_count = 0
self.last_error_time = None
def record_error(self, error_message):
current_time = time.time()
if self.last_error_time is None or current_time - self.last_error_time >= self.error_interval:
self.error_count = 1
self.last_error_time = current_time
else:
self.error_count += 1
if self.error_count >= self.error_threshold:
self.send_alert(error_message)
self.error_count = 0
def send_alert(self, error_message):
subject = "Trading Bot Alert"
message = f"An error occurred in the trading bot:\n\n{error_message}"
notification(subject, message)