Time-bucketed local telemetry for mesh RTT, peer health, and node-internal metrics. How rollups stay cheap (one row per metric per peer per bucket) and feed both the explorer and gateway routing.
Every node measures itself constantly: RTT to each mesh peer, heartbeat latencies, scanner loop durations, cache hit rates. Storing every individual sample would generate millions of rows per day per node and is wasteful — what matters is the aggregate over a meaningful window. The agorix_node_local_telemetry_rollups table compresses these signals into time-bucketed summaries that stay cheap to write and easy to query.
The table is keyed by (nodeId, metric, peerNodeId, bucketSeconds, bucketStart) so a single row holds the aggregate for one metric, one peer (or empty string for node-global metrics), one bucket size, and one bucket start time:
| Column | Purpose |
|---|---|
metric | Metric name (e.g. mesh_rtt, heartbeat_latency, block_scan_ms) |
peerNodeId | The peer this sample relates to, or empty string for global metrics |
bucketSeconds | Bucket granularity (e.g. 60 for 1-min, 300 for 5-min, 3600 for hourly) |
bucketStart | Bucket window start timestamp |
sampleCount | How many raw samples landed in this bucket |
successCount | How many of those samples were classified as successful |
valueSum | Sum of sample values (divide by sampleCount for the mean) |
valueMin / valueMax | Bucket extremes |
sampleBitmap | Compact bitmap encoding when each sample landed within the bucket — useful for sparseness detection |
metadata | Free-form JSONB for metric-specific extras |
The composite primary key means rollup writes are pure UPSERTs — increment counters and update min/max in place, never insert duplicate rows for the same window.
A single metric is typically tracked at several granularities simultaneously: a 1-minute bucket for live dashboards, a 5-minute bucket for routing decisions, an hourly bucket for trends. Each granularity gets its own primary-key tuple, so storing all three costs only three small rows per peer per window.
The cleanup policy keeps high-resolution buckets only for short windows (1m for ~6h, 5m for ~24h, 1h indefinitely) — old fine-grained rows get pruned while the hourly trend stays around.
Local writers (the gossip ping worker, scanner loops, cache instrumentation) batch their samples in memory and flush rollup deltas to PostgreSQL on a timer rather than writing per sample. This keeps the database write rate proportional to active metric+peer pairs, not raw event count.
mesh_rtt rollups to weight cohort selection — fresh peer latencies feed directly into routing scoresRollups stay on the originating node — they are not gossiped. Every node measures the network from its own vantage point, and the truth about RTT from node A to node B is meaningful primarily to node A. Aggregating across nodes would either double-count or smear the signal. The gateway and explorer combine multiple nodes' rollups when they need a network-wide view, but the storage stays decentralized.