feat: complete agent monitoring - hook, UI, and backend filter
- Add event_type and framework filters to events query endpoint - Add /agents SPA route to web-ui server - Add Agents nav link and route in frontend - Add agents page CSS (timeline, VM pills, stats panel) - Build VM status strip, activity timeline, and real-time stats - Add agentmon hook for OpenClaw (HOOK.md + handler.ts) - Add docker-compose, Dockerfile, and supporting infra files Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package postgres
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -13,20 +14,39 @@ type EventRow struct {
|
||||
Payload json.RawMessage `json:"payload"`
|
||||
}
|
||||
|
||||
func (d *DB) ListRecentEvents(ctx context.Context, limit int) ([]EventRow, error) {
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
type EventsFilter struct {
|
||||
Limit int
|
||||
EventType string
|
||||
Framework string
|
||||
}
|
||||
|
||||
func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow, error) {
|
||||
if f.Limit <= 0 {
|
||||
f.Limit = 100
|
||||
}
|
||||
if limit > 1000 {
|
||||
limit = 1000
|
||||
if f.Limit > 1000 {
|
||||
f.Limit = 1000
|
||||
}
|
||||
|
||||
rows, err := d.sql.QueryContext(ctx, `
|
||||
select event_id, ts, type, payload
|
||||
from events
|
||||
order by ts desc
|
||||
limit $1
|
||||
`, limit)
|
||||
query := "SELECT event_id, ts, type, payload FROM events WHERE 1=1"
|
||||
args := []any{}
|
||||
argN := 1
|
||||
|
||||
if f.EventType != "" {
|
||||
query += fmt.Sprintf(" AND type = $%d", argN)
|
||||
args = append(args, f.EventType)
|
||||
argN++
|
||||
}
|
||||
if f.Framework != "" {
|
||||
query += fmt.Sprintf(" AND source_framework = $%d", argN)
|
||||
args = append(args, f.Framework)
|
||||
argN++
|
||||
}
|
||||
|
||||
query += fmt.Sprintf(" ORDER BY ts DESC LIMIT $%d", argN)
|
||||
args = append(args, f.Limit)
|
||||
|
||||
rows, err := d.sql.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -40,8 +60,5 @@ limit $1
|
||||
}
|
||||
out = append(out, r)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user