-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaetherra_live_monitor.py
More file actions
151 lines (130 loc) · 4.68 KB
/
Copy pathaetherra_live_monitor.py
File metadata and controls
151 lines (130 loc) · 4.68 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2025 Aetherra Labs and Contributors
"""
🔴 AETHERRA OS LIVE ACTIVITY MONITOR
====================================
Real-time monitoring of Aetherra OS activity and performance.
Aligned to current endpoints:
- Hub Server (port 3001): /health, /status, /api/stats, /api/plugins
- Web Interface (port 8686): /api/system/status, /api/metrics/realtime
"""
# Standard library imports
import argparse
import os
import time
from datetime import datetime
from typing import Any
# Third party imports
import requests
HUB_BASE = "http://localhost:3001"
WEB_BASE = "http://localhost:8686"
def _fetch_json(url: str, timeout: float = 2.0) -> dict[str, Any] | None:
try:
r = requests.get(url, timeout=timeout)
if r.ok:
return r.json()
return None
except requests.exceptions.RequestException:
return None
def _tail_log(path: str, lines: int = 10) -> list[str]:
try:
with open(path, encoding="utf-8", errors="ignore") as f:
buf = f.readlines()
return [ln.rstrip() for ln in buf[-lines:] if ln.strip()]
except FileNotFoundError:
return []
def render_once():
print("🔴 AETHERRA OS LIVE ACTIVITY MONITOR")
print("=" * 50)
print("Monitoring real-time system activity…")
print()
# Hub server status (authoritative)
health = _fetch_json(f"{HUB_BASE}/health")
status = _fetch_json(f"{HUB_BASE}/status")
stats = _fetch_json(f"{HUB_BASE}/api/stats")
plugins = _fetch_json(f"{HUB_BASE}/api/plugins")
if health or status:
print("🟢 HUB: ONLINE")
uptime = None
if health and isinstance(health.get("uptime_seconds"), (int, float)):
uptime = int(health.get("uptime_seconds", 0))
elif status and isinstance(status.get("uptime_seconds"), (int, float)):
uptime = int(status.get("uptime_seconds", 0))
reqs = None
if health:
reqs = health.get("requests_served")
if reqs is None and stats:
reqs = stats.get("requests_served")
plugin_count = 0
if plugins and isinstance(plugins.get("plugins"), list):
plugin_count = len(plugins.get("plugins", []))
elif health and isinstance(health.get("plugins_registered"), int):
plugin_count = health.get("plugins_registered", 0)
print(
f" ⏱️ Uptime: {uptime or 0}s • 📈 Requests: {reqs or 0} • 🔌 Plugins: {plugin_count}"
)
else:
print("🔴 HUB: Not responding on localhost:3001")
# Web interface (optional)
web_status = _fetch_json(f"{WEB_BASE}/api/system/status")
metrics = _fetch_json(f"{WEB_BASE}/api/metrics/realtime")
if web_status or metrics:
print("🟢 WEB INTERFACE: ACTIVE")
if metrics:
cpu = metrics.get("cpu_usage")
mem = metrics.get("memory_usage")
rt = metrics.get("response_time")
extras = []
if isinstance(cpu, (int, float)):
extras.append(f"CPU {cpu}%")
if isinstance(mem, (int, float)):
extras.append(f"MEM {mem}%")
if isinstance(rt, (int, float)):
extras.append(f"RT {rt}ms")
if extras:
print(" " + " • ".join(extras))
else:
print("🟡 WEB INTERFACE: Not detected on localhost:8686 (optional)")
# Recent log activity
recent = _tail_log("aetherra_os.log", lines=10)
print()
print("📋 RECENT SYSTEM ACTIVITY:")
print("-" * 30)
if recent:
for line in recent:
print(f" {line}")
else:
print(" (no recent log lines or log missing)")
# Summary footer
print()
print("⚡ SYSTEM STATUS:")
print("-" * 20)
current_time = datetime.now().strftime("%H:%M:%S")
print(f"🕐 Current Time: {current_time}")
print(
"Components: Service Registry • Plugin Discovery • Memory • Hub • Web UI • Core Engine"
)
print()
print("=" * 50)
def monitor_aetherra_activity(watch_interval: int = 0):
if watch_interval <= 0:
render_once()
return
try:
while True:
os.system("cls" if os.name == "nt" else "clear")
render_once()
time.sleep(watch_interval)
except KeyboardInterrupt:
print("\n� Stopped.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Aetherra OS Live Monitor")
parser.add_argument(
"--watch",
type=int,
default=0,
help="Refresh every N seconds (0 = one-shot)",
)
args = parser.parse_args()
monitor_aetherra_activity(args.watch)