Spaces:
Build error
Build error
Update services.py
Browse files- 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 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|