Files
microdao-daarion/MONITOR-AGENT-REAL-DATA-FINAL.md
Apple 3de3c8cb36 feat: Add presence heartbeat for Matrix online status
- matrix-gateway: POST /internal/matrix/presence/online endpoint
- usePresenceHeartbeat hook with activity tracking
- Auto away after 5 min inactivity
- Offline on page close/visibility change
- Integrated in MatrixChatRoom component
2025-11-27 00:19:40 -08:00

301 lines
8.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ✅ Monitor Agent - Реальні дані (Фінальне виправлення)
**Дата:** 2025-11-23
**Статус:** ✅ Monitor Agent Service запущено, реальні дані доступні
---
## 🎯 Проблема
Monitor Agent відповідав: **"У контексті немає реальних метрик"**
### Причина:
Monitor Agent Service **не був запущений!**
---
## ✅ Рішення
### 1. Запустити Monitor Agent Service
```bash
cd /Users/apple/github-projects/microdao-daarion/services/monitor-agent-service
source venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 9500 --reload
```
**Порт:** `9500`
**URL:** `http://localhost:9500`
### 2. Перевірити стан
```bash
curl http://localhost:9500/health
```
**Очікуваний результат:**
```json
{
"status": "ok",
"service": "monitor-agent-service"
}
```
---
## 📊 Джерела реальних даних
### НОДА1 (Hetzner 144.76.224.179)
1. **NATS метрики:**
- URL: `http://144.76.224.179:8222/varz`
- Дані: connections, CPU, memory, uptime
2. **Swapper Service:**
- URL: `http://144.76.224.179:8890/status`
- Дані: моделі, VRAM, активні спеціалісти
3. **Frontend API:**
- URL: `http://localhost:8899/api/nodes/node-1-hetzner-gex44/metrics`
- Дані: CPU, RAM, Disk, Network, Status
### НОДА2 (MacBook M4 Max 192.168.1.244)
1. **Ollama API:**
- URL: `http://192.168.1.244:11434/api/tags`
- Дані: доступні моделі, розміри
2. **Swapper Service:**
- URL: `http://192.168.1.244:8890/status`
- Дані: моделі, Metal acceleration, активні спеціалісти
3. **Frontend API:**
- URL: `http://localhost:8899/api/nodes/node-2-macbook-m4max/metrics`
- Дані: CPU, RAM, GPU (Metal), Network, Status
### Останні зміни проєкту
1. **Memory Service:**
- URL: `http://localhost:8000/agents/monitor/memory`
- Дані: останні події, зміни, деплойменти
2. **Локальна файлова система:**
- Шлях: `/Users/apple/github-projects/microdao-daarion`
- Дані: останні змінені файли (`.tsx`, `.ts`, `.py`, `.yaml`, `.md`)
---
## 🔧 Функція get_real_node_metrics()
Оновлена для множинних джерел даних:
```python
async def get_real_node_metrics(node_id: str) -> Optional[Dict[str, Any]]:
"""
Отримати реальні метрики ноди з різних джерел
"""
urls = [
f"{FRONTEND_API_URL}/api/nodes/{node_id}/metrics",
f"http://localhost:8899/api/nodes/{node_id}/metrics",
]
# Додаємо прямі підключення до нод
if node_id == 'node-1' or node_id == 'node-1-hetzner-gex44':
urls.append("http://144.76.224.179:8222/varz") # NATS
urls.append("http://144.76.224.179:8890/status") # Swapper
elif node_id == 'node-2' or node_id == 'node-2-macbook-m4max':
urls.append("http://192.168.1.244:11434/api/tags") # Ollama
urls.append("http://192.168.1.244:8890/status") # Swapper
for url in urls:
try:
async with httpx.AsyncClient(timeout=3.0) as client:
response = await client.get(url)
if response.status_code == 200:
return {
'node_id': node_id,
'source': url,
'data': response.json(),
'timestamp': datetime.utcnow().isoformat()
}
except:
continue
return None
```
---
## 📝 Функція get_recent_project_changes()
Оновлена для локальних даних:
```python
async def get_recent_project_changes(limit: int = 20) -> List[Dict[str, Any]]:
"""
Отримати останні зміни проєкту з Memory Service та локально
"""
changes = []
# 1. Memory Service
try:
async with httpx.AsyncClient(timeout=3.0) as client:
response = await client.get(
f"{MEMORY_SERVICE_URL}/agents/monitor/memory",
params={"limit": limit, "agent_id": "monitor-global"}
)
if response.status_code == 200:
memories = response.json().get('memories', [])
changes.extend(memories)
except:
pass
# 2. Локальні файли
try:
project_root = Path("/Users/apple/github-projects/microdao-daarion")
if project_root.exists():
for ext in ['.tsx', '.ts', '.py', '.yaml', '.yml', '.md']:
recent_files = list(project_root.rglob(f'*{ext}'))[:5]
for file in recent_files:
stat = file.stat()
changes.append({
'type': 'file',
'action': 'modified',
'path': str(file.relative_to(project_root)),
'timestamp': datetime.fromtimestamp(stat.st_mtime).isoformat(),
'size': stat.st_size
})
except:
pass
return changes[:limit]
```
---
## 🧪 Тестування
### 1. Перевірити Monitor Agent Service
```bash
# Health check
curl http://localhost:9500/health
# Тест з реальними метриками
curl -X POST http://localhost:9500/api/agent/monitor/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Покажи реальні метрики НОДА1 та НОДА2",
"agent_id": "monitor-global",
"context": {}
}'
```
### 2. Перевірити у браузері
1. Відкрити: `http://localhost:8899/dagi-monitor`
2. Написати: **"Покажи реальні метрики НОДА1 та НОДА2"**
3. Натиснути **"Відправити"**
**Очікуваний результат:**
```
НОДА1 (Hetzner 144.76.224.179):
- Джерело: http://144.76.224.179:8222/varz
- Підключення: 15
- CPU: 2.5%
- RAM: 4096 MB
НОДА2 (MacBook M4 Max 192.168.1.244):
- Джерело: http://192.168.1.244:11434/api/tags
- Доступні моделі: 8
- Моделі: gpt-oss:latest, mistral-nemo:12b, qwen3:8b
```
### 3. Натиснути "Тест 10 змін"
**Очікуваний результат:**
- 10 компактних повідомлень про зміни
- Кожне займає 1 рядок
- З реальними даними про НОДА1 та НОДА2
---
## 🔄 Автоматизація
### Додати Monitor Agent Service до автозапуску
**Файл:** `docker-compose.yml` (якщо потрібно)
```yaml
monitor-agent-service:
build: ./services/monitor-agent-service
ports:
- "9500:9500"
environment:
- OLLAMA_BASE_URL=http://localhost:11434
- MISTRAL_MODEL=mistral-nemo:12b
- MEMORY_SERVICE_URL=http://localhost:8000
- FRONTEND_API_URL=http://localhost:8899
restart: unless-stopped
```
**Або через systemd (Linux):**
```bash
sudo systemctl enable monitor-agent.service
sudo systemctl start monitor-agent.service
```
---
## 📊 Результат
### До виправлення:
```
У контексті немає реальних метрик нод. Реальні метрики недоступні зараз.
```
### Після виправлення:
```
НОДА1 (Hetzner 144.76.224.179):
- Джерело: http://144.76.224.179:8890/status
- Активні моделі: qwen3-8b
- VRAM: 8.5 GB / 20 GB
- CPU: 0.13%
- RAM: 42.85 MiB
НОДА2 (MacBook M4 Max 192.168.1.244):
- Джерело: http://192.168.1.244:11434/api/tags
- Доступні моделі: 8
- Моделі: gpt-oss:latest, mistral-nemo:12b, qwen3:8b
📝 ОСТАННІ ЗМІНИ (12):
1. service modified: nodes/node-1/swapper-service
2. agent deployed: nodes/node-1/agents/yaromir
3. config modified: src/pages/DagiMonitorPage.tsx
4. file modified: src/services/projectChangeTracker.ts
...
```
---
## ✅ Чекліст
- [x] Monitor Agent Service запущено на порту 9500
- [x] `get_real_node_metrics()` підключається до НОДА1 та НОДА2
- [x] `get_recent_project_changes()` збирає локальні та API дані
- [x] System prompt вимагає використання ТІЛЬКИ реальних даних
- [x] Тестування через API (`curl`)
- [x] Тестування через UI (`http://localhost:8899/dagi-monitor`)
- [x] Компактні повідомлення (1 рядок)
- [x] Real-time відстеження (кожні 5 секунд)
---
**Статус:** ✅ Готово! Monitor Agent тепер показує реальні метрики!
**Тестуйте:** `http://localhost:8899/dagi-monitor`