Add network bandwidth to node_stats #42

Closed
opened 2026-03-20 21:36:13 +00:00 by mahmoud · 5 comments
Owner

Description

Add network RX/TX bytes per second to NodeStats so users can monitor bandwidth usage per node.

Fields to add to NodeStats:

  • network_rx_bytes_per_sec: u64
  • network_tx_bytes_per_sec: u64
  • network_rx_bytes_total: u64
  • network_tx_bytes_total: u64

Implementation

  • Use sysinfo Networks for collection
  • Two-phase sampling (same as CPU)
  • Exclude loopback interface
  • Include in heartbeat to explorer
  • Show in admin page UI
  • Show in node page UI

Definition of Done

  • NodeStats has network fields
  • StatsCollector collects network bandwidth
  • Heartbeat includes network stats
  • Explorer ExplorerNode has network fields
  • Admin UI shows RX/TX bandwidth
  • formatBandwidth() helper in dashboard.js
### Description Add network RX/TX bytes per second to NodeStats so users can monitor bandwidth usage per node. Fields to add to NodeStats: - network_rx_bytes_per_sec: u64 - network_tx_bytes_per_sec: u64 - network_rx_bytes_total: u64 - network_tx_bytes_total: u64 ### Implementation - Use sysinfo Networks for collection - Two-phase sampling (same as CPU) - Exclude loopback interface - Include in heartbeat to explorer - Show in admin page UI - Show in node page UI ### Definition of Done - [x] NodeStats has network fields - [x] StatsCollector collects network bandwidth - [x] Heartbeat includes network stats - [x] Explorer ExplorerNode has network fields - [x] Admin UI shows RX/TX bandwidth - [x] formatBandwidth() helper in dashboard.js
mahmoud self-assigned this 2026-03-20 21:36:16 +00:00
mahmoud added this to the ACTIVE project 2026-03-20 21:36:19 +00:00
mahmoud added this to the now milestone 2026-03-20 21:36:24 +00:00
Author
Owner

Implementation Spec for Issue #42: Add Network Bandwidth to NodeStats

Objective

Add network RX/TX bytes-per-second and total counters to NodeStats so users can monitor bandwidth usage per node in both the local admin dashboard and the explorer-aggregated node view.

Requirements

  • Add four new fields to NodeStats: network_rx_bytes_per_sec (u64), network_tx_bytes_per_sec (u64), network_rx_bytes_total (u64), network_tx_bytes_total (u64)
  • Use sysinfo::Networks to collect network data, excluding loopback interfaces
  • Two-phase sampling (piggyback on existing 200ms CPU sleep)
  • Include network stats in heartbeat to explorer
  • Add corresponding fields to ExplorerNode schema
  • Display RX/TX bandwidth in admin + node page UIs
  • Add formatBandwidth() JS helper

Files to Modify

File Change
schemas/cloud/cloud.oschema Add 4 network fields to NodeStats
schemas/explorer/explorer.oschema Add 4 fields to ExplorerNode + node_heartbeat params
crates/hero_compute_server/src/cloud/stats.rs Add Networks to StatsCollector, two-phase sampling
crates/hero_compute_server/src/cloud/rpc.rs Add network fields to node_stats() JSON
crates/hero_compute_server/src/heartbeat_sender.rs Add network fields to heartbeat payload
crates/hero_compute_explorer/src/explorer/rpc.rs Store network fields in node_heartbeat handler
crates/hero_compute_ui/static/js/dashboard.js Add formatBandwidth() + formatBytes() helpers
crates/hero_compute_ui/templates/admin.html Add network health card with sparkline
crates/hero_compute_ui/templates/nodes.html Add network stats to live stats + explorer cards

Implementation Steps

  1. Schema updates — Add network fields to cloud.oschema (NodeStats) and explorer.oschema (ExplorerNode + node_heartbeat)
  2. Regenerate types — cargo build to regenerate types_generated.rs and rpc_generated.rs
  3. StatsCollector — Add sysinfo::Networks, two-phase sampling, exclude loopback
  4. RPC + Heartbeat — Add network fields to node_stats() response and heartbeat sender
  5. Explorer handler — Store network fields in node_heartbeat handler
  6. Frontend helpers — Add formatBandwidth() and formatBytes() to dashboard.js
  7. Admin UI — Add network health card with sparkline
  8. Node UI — Add network stats to live stats section + explorer node cards

Acceptance Criteria

  • NodeStats has network fields in oschema
  • StatsCollector uses sysinfo::Networks with two-phase sampling
  • node_stats() RPC includes network fields
  • Heartbeat sends network fields to explorer
  • ExplorerNode has network fields
  • Explorer stores network data from heartbeat
  • formatBandwidth() helper in dashboard.js
  • Admin page shows RX/TX bandwidth with sparkline
  • Node page shows RX/TX bandwidth in live stats
  • cargo build succeeds for both server and explorer
## Implementation Spec for Issue #42: Add Network Bandwidth to NodeStats ### Objective Add network RX/TX bytes-per-second and total counters to `NodeStats` so users can monitor bandwidth usage per node in both the local admin dashboard and the explorer-aggregated node view. ### Requirements - Add four new fields to `NodeStats`: `network_rx_bytes_per_sec` (u64), `network_tx_bytes_per_sec` (u64), `network_rx_bytes_total` (u64), `network_tx_bytes_total` (u64) - Use `sysinfo::Networks` to collect network data, excluding loopback interfaces - Two-phase sampling (piggyback on existing 200ms CPU sleep) - Include network stats in heartbeat to explorer - Add corresponding fields to `ExplorerNode` schema - Display RX/TX bandwidth in admin + node page UIs - Add `formatBandwidth()` JS helper ### Files to Modify | File | Change | |------|--------| | `schemas/cloud/cloud.oschema` | Add 4 network fields to NodeStats | | `schemas/explorer/explorer.oschema` | Add 4 fields to ExplorerNode + node_heartbeat params | | `crates/hero_compute_server/src/cloud/stats.rs` | Add Networks to StatsCollector, two-phase sampling | | `crates/hero_compute_server/src/cloud/rpc.rs` | Add network fields to node_stats() JSON | | `crates/hero_compute_server/src/heartbeat_sender.rs` | Add network fields to heartbeat payload | | `crates/hero_compute_explorer/src/explorer/rpc.rs` | Store network fields in node_heartbeat handler | | `crates/hero_compute_ui/static/js/dashboard.js` | Add formatBandwidth() + formatBytes() helpers | | `crates/hero_compute_ui/templates/admin.html` | Add network health card with sparkline | | `crates/hero_compute_ui/templates/nodes.html` | Add network stats to live stats + explorer cards | ### Implementation Steps 1. **Schema updates** — Add network fields to cloud.oschema (NodeStats) and explorer.oschema (ExplorerNode + node_heartbeat) 2. **Regenerate types** — cargo build to regenerate types_generated.rs and rpc_generated.rs 3. **StatsCollector** — Add sysinfo::Networks, two-phase sampling, exclude loopback 4. **RPC + Heartbeat** — Add network fields to node_stats() response and heartbeat sender 5. **Explorer handler** — Store network fields in node_heartbeat handler 6. **Frontend helpers** — Add formatBandwidth() and formatBytes() to dashboard.js 7. **Admin UI** — Add network health card with sparkline 8. **Node UI** — Add network stats to live stats section + explorer node cards ### Acceptance Criteria - [ ] NodeStats has network fields in oschema - [ ] StatsCollector uses sysinfo::Networks with two-phase sampling - [ ] node_stats() RPC includes network fields - [ ] Heartbeat sends network fields to explorer - [ ] ExplorerNode has network fields - [ ] Explorer stores network data from heartbeat - [ ] formatBandwidth() helper in dashboard.js - [ ] Admin page shows RX/TX bandwidth with sparkline - [ ] Node page shows RX/TX bandwidth in live stats - [ ] cargo build succeeds for both server and explorer
Author
Owner

Test Results

  • Build: pass
  • Tests run: 27
  • Passed: 27
  • Failed: 0

Breakdown by crate

Crate Binary Tests Result
hero_compute_explorer lib 2 ok
hero_compute_explorer main 5 ok
hero_compute_server lib 9 ok
hero_compute_server main 11 ok
hero_compute_explorer doc-tests 3 ignored ok
hero_compute_server doc-tests 2 ignored ok

All tests passing on development branch (commit c457b8a).

## Test Results - **Build**: pass - **Tests run**: 27 - **Passed**: 27 - **Failed**: 0 ### Breakdown by crate | Crate | Binary | Tests | Result | |-------|--------|------:|--------| | hero_compute_explorer | lib | 2 | ok | | hero_compute_explorer | main | 5 | ok | | hero_compute_server | lib | 9 | ok | | hero_compute_server | main | 11 | ok | | hero_compute_explorer | doc-tests | 3 ignored | ok | | hero_compute_server | doc-tests | 2 ignored | ok | All tests passing on `development` branch (commit c457b8a).
Author
Owner

Implementation Summary: Network Statistics

20 files changed | ~363 lines added


Changes

Schema (2 files)

  • schemas/cloud/cloud.oschema — Added 4 network fields to NodeStats embedded type
  • schemas/explorer/explorer.oschema — Added 4 network fields to ExplorerNode + node_heartbeat params

Auto-generated (8 files)

  • types_generated.rs, rpc_generated.rs, osis_server_generated.rs, openrpc.json, types_wasm_generated.rs, sdk/js/types_generated.js — for both server and explorer crates

Backend (4 files)

  • crates/hero_compute_server/src/cloud/stats.rs — Added sysinfo::Networks to StatsCollector, two-phase network sampling (piggybacks on CPU 200ms sleep), excludes loopback interfaces, computes bytes/sec and totals
  • crates/hero_compute_server/src/cloud/rpc.rs — Added 4 network fields to node_stats() JSON response
  • crates/hero_compute_server/src/heartbeat_sender.rs — Added 4 network fields to heartbeat payload
  • crates/hero_compute_explorer/src/explorer/rpc.rs — Added 4 network params to node_heartbeat handler, stores on ExplorerNode in both update and create branches

Frontend (3 files)

  • crates/hero_compute_ui/static/js/dashboard.js — Added formatBandwidth() and formatBytes() helpers, updated explorer node card rendering with network stats
  • crates/hero_compute_ui/templates/admin.html — Added Network health card with sparkline (bi-arrow-down-up icon, cyan color)
  • crates/hero_compute_ui/templates/nodes.html — Added Network health card to live stats section with sparkline

Test Results

Check Status
Build PASS
Tests 27 passed, 0 failed
## Implementation Summary: Network Statistics **20 files changed** | **~363 lines added** --- ### Changes #### Schema (2 files) - `schemas/cloud/cloud.oschema` — Added 4 network fields to `NodeStats` embedded type - `schemas/explorer/explorer.oschema` — Added 4 network fields to `ExplorerNode` + `node_heartbeat` params #### Auto-generated (8 files) - `types_generated.rs`, `rpc_generated.rs`, `osis_server_generated.rs`, `openrpc.json`, `types_wasm_generated.rs`, `sdk/js/types_generated.js` — for both **server** and **explorer** crates #### Backend (4 files) - `crates/hero_compute_server/src/cloud/stats.rs` — Added `sysinfo::Networks` to `StatsCollector`, two-phase network sampling (piggybacks on CPU 200ms sleep), excludes loopback interfaces, computes bytes/sec and totals - `crates/hero_compute_server/src/cloud/rpc.rs` — Added 4 network fields to `node_stats()` JSON response - `crates/hero_compute_server/src/heartbeat_sender.rs` — Added 4 network fields to heartbeat payload - `crates/hero_compute_explorer/src/explorer/rpc.rs` — Added 4 network params to `node_heartbeat` handler, stores on `ExplorerNode` in both update and create branches #### Frontend (3 files) - `crates/hero_compute_ui/static/js/dashboard.js` — Added `formatBandwidth()` and `formatBytes()` helpers, updated explorer node card rendering with network stats - `crates/hero_compute_ui/templates/admin.html` — Added Network health card with sparkline (`bi-arrow-down-up` icon, cyan color) - `crates/hero_compute_ui/templates/nodes.html` — Added Network health card to live stats section with sparkline --- ### Test Results | Check | Status | |-------|--------| | Build | :white_check_mark: PASS | | Tests | :white_check_mark: **27 passed, 0 failed** |
Author
Owner

Implementation committed: d595df9

Browse: d595df9

Implementation committed: `d595df9` Browse: https://forge.ourworld.tf/lhumina_code/hero_compute/commit/d595df9
Author
Owner

Done

Done
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_compute#42
No description provided.