vnai 2.0.2__py3-none-any.whl → 2.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vnai/__init__.py +291 -72
- vnai/beam/__init__.py +2 -2
- vnai/beam/metrics.py +207 -57
- vnai/beam/pulse.py +122 -29
- vnai/beam/quota.py +507 -102
- vnai/flow/__init__.py +7 -2
- vnai/flow/queue.py +142 -55
- vnai/flow/relay.py +476 -149
- vnai/scope/__init__.py +7 -2
- vnai/scope/profile.py +858 -219
- vnai/scope/promo.py +197 -55
- vnai/scope/state.py +246 -71
- {vnai-2.0.2.dist-info → vnai-2.0.3.dist-info}/METADATA +1 -1
- vnai-2.0.3.dist-info/RECORD +16 -0
- {vnai-2.0.2.dist-info → vnai-2.0.3.dist-info}/WHEEL +1 -1
- vnai-2.0.2.dist-info/RECORD +0 -16
- {vnai-2.0.2.dist-info → vnai-2.0.3.dist-info}/top_level.txt +0 -0
vnai/beam/pulse.py
CHANGED
@@ -1,31 +1,124 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
##
|
2
|
+
|
3
|
+
##
|
4
|
+
|
5
|
+
|
6
|
+
import threading
|
7
|
+
import time
|
4
8
|
from datetime import datetime
|
9
|
+
|
5
10
|
class Monitor:
|
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
|
-
|
11
|
+
#--
|
12
|
+
|
13
|
+
_instance = None
|
14
|
+
_lock = threading.Lock()
|
15
|
+
|
16
|
+
def __new__(cls):
|
17
|
+
with cls._lock:
|
18
|
+
if cls._instance is None:
|
19
|
+
cls._instance = super(Monitor, cls).__new__(cls)
|
20
|
+
cls._instance._initialize()
|
21
|
+
return cls._instance
|
22
|
+
|
23
|
+
def _initialize(self):
|
24
|
+
#--
|
25
|
+
self.health_status = "healthy"
|
26
|
+
self.last_check = time.time()
|
27
|
+
self.check_interval = 300 ##
|
28
|
+
|
29
|
+
self.error_count = 0
|
30
|
+
self.warning_count = 0
|
31
|
+
self.status_history = []
|
32
|
+
|
33
|
+
##
|
34
|
+
|
35
|
+
self._start_background_check()
|
36
|
+
|
37
|
+
def _start_background_check(self):
|
38
|
+
#--
|
39
|
+
def check_health():
|
40
|
+
while True:
|
41
|
+
try:
|
42
|
+
self.check_health()
|
43
|
+
except:
|
44
|
+
pass ##
|
45
|
+
|
46
|
+
time.sleep(self.check_interval)
|
47
|
+
|
48
|
+
thread = threading.Thread(target=check_health, daemon=True)
|
49
|
+
thread.start()
|
50
|
+
|
51
|
+
def check_health(self):
|
52
|
+
#--
|
53
|
+
from vnai.beam.metrics import collector
|
54
|
+
from vnai.beam.quota import guardian
|
55
|
+
|
56
|
+
##
|
57
|
+
|
58
|
+
self.last_check = time.time()
|
59
|
+
|
60
|
+
##
|
61
|
+
|
62
|
+
metrics_summary = collector.get_metrics_summary()
|
63
|
+
has_errors = metrics_summary.get("error", 0) > 0
|
64
|
+
|
65
|
+
##
|
66
|
+
|
67
|
+
resource_usage = guardian.usage()
|
68
|
+
high_usage = resource_usage > 80 ##
|
69
|
+
|
70
|
+
|
71
|
+
##
|
72
|
+
|
73
|
+
if has_errors and high_usage:
|
74
|
+
self.health_status = "critical"
|
75
|
+
self.error_count += 1
|
76
|
+
elif has_errors or high_usage:
|
77
|
+
self.health_status = "warning"
|
78
|
+
self.warning_count += 1
|
79
|
+
else:
|
80
|
+
self.health_status = "healthy"
|
81
|
+
|
82
|
+
##
|
83
|
+
|
84
|
+
self.status_history.append({
|
85
|
+
"timestamp": datetime.now().isoformat(),
|
86
|
+
"status": self.health_status,
|
87
|
+
"metrics": metrics_summary,
|
88
|
+
"resource_usage": resource_usage
|
89
|
+
})
|
90
|
+
|
91
|
+
##
|
92
|
+
|
93
|
+
if len(self.status_history) > 10:
|
94
|
+
self.status_history = self.status_history[-10:]
|
95
|
+
|
96
|
+
return self.health_status
|
97
|
+
|
98
|
+
def report(self):
|
99
|
+
#--
|
100
|
+
##
|
101
|
+
|
102
|
+
if time.time() - self.last_check > self.check_interval:
|
103
|
+
self.check_health()
|
104
|
+
|
105
|
+
return {
|
106
|
+
"status": self.health_status,
|
107
|
+
"last_check": datetime.fromtimestamp(self.last_check).isoformat(),
|
108
|
+
"error_count": self.error_count,
|
109
|
+
"warning_count": self.warning_count,
|
110
|
+
"history": self.status_history[-3:], ##
|
111
|
+
|
112
|
+
}
|
113
|
+
|
114
|
+
def reset(self):
|
115
|
+
#--
|
116
|
+
self.health_status = "healthy"
|
117
|
+
self.error_count = 0
|
118
|
+
self.warning_count = 0
|
119
|
+
self.status_history = []
|
120
|
+
self.last_check = time.time()
|
121
|
+
|
122
|
+
##
|
123
|
+
|
124
|
+
monitor = Monitor()
|