Skip to content

DISTRIBUTED BRAIN METRICS UI

Distributed Brain: Metrics UI and Frontend Integration

This document summarizes recent changes related to displaying real-time metrics in distributed_brain. The purpose is to visualize transmission failure/backpressure indicators during operation and provide a simple front-end display and a source for future graphing.

Modified files (overview)

  • evospikenet/api_modules/distributed_ws.py:
  • New/changed endpoints
    • GET /distributed_brain/metrics — Returns the current counters (send_timeouts, broadcast_drops, persist_drops, connected_clients, etc.) in JSON.
    • POST /distributed_brain/publish_log — Existing log publishing REST API (continued)
    • WebSocket /ws/distributed_brain/logs — Real-time distribution for front end (with authentication)
  • Internal: Implements queues for backpressure, persistent batch flusher, Redis Pub/Sub (optional), etc.

  • frontend/pages/distributed_brain.py:

  • Added a small text display area for metrics to the log display toolbar (div#distributed-metrics).
  • Added canvas#distributed-metrics-canvas for drawing metrics to the toolbar (placeholder for drawing graphs in Chart.js etc.).
  • Poll fetch('/distributed_brain/metrics') on the client side every 5 seconds, format the received JSON into div#distributed-metrics and display it (currently displayed as a numeric value).

API schema (simple)

  • GET /distributed_brain/metrics → 200 JSON
{
  "send_timeouts": 12,
  "broadcast_drops": 3,
  "persist_drops": 0,
  "connected_clients": 2,
  "last_update": "2026-03-09T12:34:56.789Z"
}

Frontend behavior (current)

  • Start WS connection after page load (/ws/distributed_brain/logs).
  • At the same time, fetch /distributed_brain/metrics every 5 seconds and display a simple status on the toolbar. Appears in: distributed-metrics on the right side of the toolbar and canvas for graphs.
  • Currently only text is displayed, canvas is a placeholder for graph display.

Chart.js / About graphing (current status and next steps)

  • Change: canvas#distributed-metrics-canvas has been added. Library installation and initialization scripts such as Chart.js are not applied. Suggested work next:
  • Load Chart.js, hold a buffer of time series data (e.g. 60 points) and draw a line graph.
  • Fetch interval, buffer length, and drawing style can be changed using front settings.

Activation/confirmation steps

  1. Restart the api container to load the latest code. example:
docker compose up -d --build api
  1. Once the API starts, open the dashboard (frontend/pages/distributed_brain.py) in your browser and notice that the metrics are updated every 5 seconds in the top right corner of the screen.

  2. To check the metrics, you can get them directly with curl:

curl -sS http://localhost:8000/distributed_brain/metrics | jq

Environment variables/operation notes

  • DISTRIBUTED_WS_REDIS (optional): Enables inter-instance broadcasting when given a Redis URL.
  • Adjust the send timeout and queue size using environment variables such as DISTRIBUTED_WS_SEND_TIMEOUT (see in evospikenet/api_modules/distributed_ws.py).
  • If you use Prometheus, prometheus-client must be installed (already included in the Docker image).

Draft release note (short)

  • Added real-time metrics display of distributed brain to the front end (added numerical display and graph canvas to the toolbar). The backend provides GET /distributed_brain/metrics for metrics. Time series graphs using Chart.js will be enabled in the next phase.

Create the English version docs/DISTRIBUTED_BRAIN_METRICS_UI.en.md if necessary. If you want to apply the chart implementation (Chart.js built-in) now, do you want to continue implementing it?