mirror of
https://github.com/d0zingcat/alert-message-center.git
synced 2026-05-13 15:09:19 +00:00
2.3 KiB
2.3 KiB
description
| description |
|---|
| System Dashboard and Monitoring Maintenance |
Dashboard and Monitoring Workflow
This workflow describes how to maintain and extend the System Load dashboard and the underlying statistics API.
Architecture
-
Backend Statistics API:
- File:
apps/server/src/api.ts - Endpoint:
GET /api/stats(Requires Admin) - Logic: Aggregates
alert_tasksandalert_logsusing Drizzle ORM. - Key Metrics:
alertsReceived: Total task count.plannedMessages: Sum ofrecipientCountacross tasks.successCount: Sum ofsuccessCount.failedCount: calculated asplannedMessages - successCount.
- File:
-
Frontend Dashboard:
- File:
apps/web/src/views/SystemLoadView.tsx - Component:
SystemLoadView - Features:
- 10s auto-refresh interval.
- SVG-based custom Gauges for success rate.
- Metric cards for immediate feedback.
- Live status indicator with breathing animation.
- Audit Log: A detailed table showing recent alert tasks, capturing the timestamp, topic, associated Sender (via personal token), and success counts.
- File:
Common Tasks
1. Extending Metrics
To add a new metric (e.g., average delivery time):
- Update
apps/server/src/api.tsin the/statshandler. - Add the new fields to the query using Drizzle's
avg,min,max, etc. - Update the
Statsinterface inapps/web/src/views/SystemLoadView.tsx. - Add a new
MetricCardor a column to the table.
2. Tuning Refresh Rates
If the 10s refresh is too aggressive:
- Change the interval in
useEffectwithinSystemLoadView.tsx. - Balance between "real-time feel" and server load.
3. Debugging Type Erasure Issues
When working with Hono's RPC client (hc):
- The client in
apps/web/src/lib/client.tsis currently cast asanyto avoid complex type inference circularities. - If adding new endpoints, ensure they are correctly routed in
apps/server/src/index.tsso they appear inAppType.
Performance Considerations
- The
/statsendpoint uses standard SQL aggregations. - For extremely large datasets, consider adding an index on
alert_tasks(created_at, topic_slug). - The dashboard is restricted to Admins to minimize the impact of frequent polling.