Skip to content

WebSocket Metrics Endpoint for Real-Time Broker Monitoring#6

Open
otabek05 wants to merge 5 commits into
otabek05:feat/ws-metrics-endpointfrom
mqttRust:feat/ws-metrics-endpoint
Open

WebSocket Metrics Endpoint for Real-Time Broker Monitoring#6
otabek05 wants to merge 5 commits into
otabek05:feat/ws-metrics-endpointfrom
mqttRust:feat/ws-metrics-endpoint

Conversation

@otabek05
Copy link
Copy Markdown
Owner

@otabek05 otabek05 commented May 7, 2026

feat: add WebSocket metrics endpoint for real-time broker monitoring

Branch: feat/ws-metrics-endpointmain

Summary

  • Add GET /api/v1/ws/metrics WebSocket endpoint that pushes a JSON metrics frame every second
  • Each frame includes process memory (MB), CPU %, connected client count, and active topics
  • New GetStats admin command wired through the engine's command channel for non-blocking stat queries

Changes

File What Changed
src/api/controllers/metrics.rs New WS handler; streams MetricsFrame every 1 s via sysinfo + engine query
src/api/router.rs Registered /api/v1/ws/metrics route
src/engine/commands.rs Added GetStats(oneshot::Sender<(usize, Vec<TopicInfo>)>) variant
src/engine/engine.rs Handles GetStats — delegates to client_service and topic_service
src/services/session.rs Added client_count() -> usize helper
Cargo.toml / Cargo.lock Added sysinfo dependency for process-level metrics

Test Plan

  • Connect a WebSocket client to ws://<host>/api/v1/ws/metrics
  • Verify frames arrive at ~1 s intervals
  • Confirm client_count changes as MQTT clients connect/disconnect
  • Confirm memory_mb and cpu_percent reflect real process stats
  • Verify connection closes cleanly when the client disconnects

Related Issue

Closes #

otabek05 and others added 2 commits May 7, 2026 17:46
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@otabek05 otabek05 requested a review from Sardor-M May 7, 2026 08:55
@otabek05 otabek05 added feature New feature or request feature-suggestion Feature suggestion to the project labels May 7, 2026
otabek05 and others added 3 commits May 8, 2026 09:15
…install guides

- Build React with Vite → embed via rust-embed into Rust binary (single binary)
- Serve React SPA from axum fallback handler; assets served by content type
- Restructure router: auth middleware only on /api/v1 routes, SPA bypasses it
- Config default path: /etc/coremq/config.yaml (fallback to local for dev)
- Data default path: /etc/coremq/data/coremq.redb (COREMQ_DATA env override)
- config.yaml updated to use /etc/coremq/ paths for Casbin model/policy
- axios.ts: use window.location.origin in production, port 18083 in dev
- Dockerfile: 3-stage build (node → rust → debian-slim runtime)
- docker-compose.yml: all ports exposed, /etc/coremq volume mounted
- build.rs: creates client/dist/ if missing so rust-embed always compiles
- Makefile: add build, build-client, build-server, docker-*, install-config targets
- docs/install-linux.md, docs/install-macos.md, docs/install-windows.md added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… run

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request feature-suggestion Feature suggestion to the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants