shaheerawan3 commited on
Commit
5a968ca
·
verified ·
1 Parent(s): 6801f36

Update services.py

Browse files
Files changed (1) hide show
  1. services.py +25 -4
services.py CHANGED
@@ -17,11 +17,32 @@ import os
17
  from prometheus_client import Counter, Histogram
18
 
19
  class MonitoringService:
 
 
 
 
 
 
 
 
20
  def __init__(self):
21
- # Use more specific metric names to avoid conflicts
22
- self.login_attempts_metric = Counter('app_login_attempts_total', 'Total login attempts')
23
- self.account_checks_metric = Counter('app_account_checks_total', 'Total account activity checks')
24
- self.response_time_metric = Histogram('app_response_time_seconds', 'Response time in seconds')
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def check_account_activity(self, account_id):
27
  activity_data = self._get_activity_data(account_id)
 
17
  from prometheus_client import Counter, Histogram
18
 
19
  class MonitoringService:
20
+ _instance = None
21
+
22
+ def __new__(cls):
23
+ if cls._instance is None:
24
+ cls._instance = super(MonitoringService, cls).__new__(cls)
25
+ cls._instance.initialized = False
26
+ return cls._instance
27
+
28
  def __init__(self):
29
+ if not self.initialized:
30
+ self.login_attempts_metric = Counter(
31
+ 'app_login_attempts_total',
32
+ 'Total login attempts',
33
+ ['status']
34
+ )
35
+ self.account_checks_metric = Counter(
36
+ 'app_account_checks_total',
37
+ 'Total account activity checks',
38
+ ['platform']
39
+ )
40
+ self.response_time_metric = Histogram(
41
+ 'app_response_time_seconds',
42
+ 'Response time in seconds',
43
+ ['endpoint']
44
+ )
45
+ self.initialized = True
46
 
47
  def check_account_activity(self, account_id):
48
  activity_data = self._get_activity_data(account_id)