vnai 2.0.2__py3-none-any.whl → 2.0.4__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 +265 -72
- vnai/beam/__init__.py +5 -2
- vnai/beam/metrics.py +182 -57
- vnai/beam/pulse.py +107 -29
- vnai/beam/quota.py +479 -102
- vnai/flow/__init__.py +5 -2
- vnai/flow/queue.py +131 -55
- vnai/flow/relay.py +439 -149
- vnai/scope/__init__.py +5 -2
- vnai/scope/profile.py +762 -219
- vnai/scope/promo.py +249 -55
- vnai/scope/state.py +220 -71
- {vnai-2.0.2.dist-info → vnai-2.0.4.dist-info}/METADATA +4 -5
- vnai-2.0.4.dist-info/RECORD +16 -0
- {vnai-2.0.2.dist-info → vnai-2.0.4.dist-info}/WHEEL +1 -1
- vnai-2.0.2.dist-info/RECORD +0 -16
- {vnai-2.0.2.dist-info → vnai-2.0.4.dist-info}/top_level.txt +0 -0
vnai/beam/pulse.py
CHANGED
@@ -1,31 +1,109 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# vnai/beam/pulse.py
|
2
|
+
# System health and performance monitoring
|
3
|
+
|
4
|
+
import threading
|
5
|
+
import time
|
4
6
|
from datetime import datetime
|
7
|
+
|
5
8
|
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
|
-
|
9
|
+
"""Monitors system health and performance"""
|
10
|
+
|
11
|
+
_instance = None
|
12
|
+
_lock = threading.Lock()
|
13
|
+
|
14
|
+
def __new__(cls):
|
15
|
+
with cls._lock:
|
16
|
+
if cls._instance is None:
|
17
|
+
cls._instance = super(Monitor, cls).__new__(cls)
|
18
|
+
cls._instance._initialize()
|
19
|
+
return cls._instance
|
20
|
+
|
21
|
+
def _initialize(self):
|
22
|
+
"""Initialize monitor"""
|
23
|
+
self.health_status = "healthy"
|
24
|
+
self.last_check = time.time()
|
25
|
+
self.check_interval = 300 # seconds
|
26
|
+
self.error_count = 0
|
27
|
+
self.warning_count = 0
|
28
|
+
self.status_history = []
|
29
|
+
|
30
|
+
# Start background health check thread
|
31
|
+
self._start_background_check()
|
32
|
+
|
33
|
+
def _start_background_check(self):
|
34
|
+
"""Start background health check thread"""
|
35
|
+
def check_health():
|
36
|
+
while True:
|
37
|
+
try:
|
38
|
+
self.check_health()
|
39
|
+
except:
|
40
|
+
pass # Don't let errors stop the monitor
|
41
|
+
time.sleep(self.check_interval)
|
42
|
+
|
43
|
+
thread = threading.Thread(target=check_health, daemon=True)
|
44
|
+
thread.start()
|
45
|
+
|
46
|
+
def check_health(self):
|
47
|
+
"""Check system health status"""
|
48
|
+
from vnai.beam.metrics import collector
|
49
|
+
from vnai.beam.quota import guardian
|
50
|
+
|
51
|
+
# Record check time
|
52
|
+
self.last_check = time.time()
|
53
|
+
|
54
|
+
# Check metrics collector health
|
55
|
+
metrics_summary = collector.get_metrics_summary()
|
56
|
+
has_errors = metrics_summary.get("error", 0) > 0
|
57
|
+
|
58
|
+
# Check resource usage
|
59
|
+
resource_usage = guardian.usage()
|
60
|
+
high_usage = resource_usage > 80 # Over 80% of rate limits
|
61
|
+
|
62
|
+
# Determine health status
|
63
|
+
if has_errors and high_usage:
|
64
|
+
self.health_status = "critical"
|
65
|
+
self.error_count += 1
|
66
|
+
elif has_errors or high_usage:
|
67
|
+
self.health_status = "warning"
|
68
|
+
self.warning_count += 1
|
69
|
+
else:
|
70
|
+
self.health_status = "healthy"
|
71
|
+
|
72
|
+
# Record health status
|
73
|
+
self.status_history.append({
|
74
|
+
"timestamp": datetime.now().isoformat(),
|
75
|
+
"status": self.health_status,
|
76
|
+
"metrics": metrics_summary,
|
77
|
+
"resource_usage": resource_usage
|
78
|
+
})
|
79
|
+
|
80
|
+
# Keep history limited to last 10 entries
|
81
|
+
if len(self.status_history) > 10:
|
82
|
+
self.status_history = self.status_history[-10:]
|
83
|
+
|
84
|
+
return self.health_status
|
85
|
+
|
86
|
+
def report(self):
|
87
|
+
"""Get health report"""
|
88
|
+
# Ensure we have a fresh check if last one is old
|
89
|
+
if time.time() - self.last_check > self.check_interval:
|
90
|
+
self.check_health()
|
91
|
+
|
92
|
+
return {
|
93
|
+
"status": self.health_status,
|
94
|
+
"last_check": datetime.fromtimestamp(self.last_check).isoformat(),
|
95
|
+
"error_count": self.error_count,
|
96
|
+
"warning_count": self.warning_count,
|
97
|
+
"history": self.status_history[-3:], # Last 3 entries
|
98
|
+
}
|
99
|
+
|
100
|
+
def reset(self):
|
101
|
+
"""Reset health monitor"""
|
102
|
+
self.health_status = "healthy"
|
103
|
+
self.error_count = 0
|
104
|
+
self.warning_count = 0
|
105
|
+
self.status_history = []
|
106
|
+
self.last_check = time.time()
|
107
|
+
|
108
|
+
# Create singleton instance
|
109
|
+
monitor = Monitor()
|