Appearance
Metrics
The framework collects metrics at multiple levels: opcode, session, node, and network-wide. These are available via support::session_metrics on each connection and aggregated into support::node_report for the entire node.
metric_counter — Atomic Counter
The basic building block for metrics is metric_counter:
cpp
struct metric_counter {
void add(uint64_t value); // Increment by value
// Tracks total, current_period, and last_time
};It provides lock-free counting with period tracking for windowed aggregation.
opcode_metrics — Per-Opcode Counters
Each opcode within a connection tracks its own read/write counters:
cpp
struct opcode_metrics {
metric_counter read_bytes_;
metric_counter write_bytes_;
metric_counter read_count_;
metric_counter write_count_;
void reset_metrics_window();
};Note: opcode_report (used in node_report) has the same structure but with plain uint64_t fields instead of metric_counter — it is a snapshot, not a live counter.
session_metrics — Per-Connection Metrics
cpp
struct session_metrics {
metric_counter total_read_bytes_;
metric_counter total_write_bytes_;
int64_t connected_at_;
std::array<opcode_metrics, 50> opcodes_;
latency_metrics latency_;
metric_counter quota_warnings_;
metric_counter quota_rejects_;
void reset_metrics_window();
};latency_metrics — Round-Trip Latency
cpp
struct latency_metrics {
uint64_t last_; // Last measured latency
uint64_t min_; // Minimum observed
uint64_t high_; // Maximum observed
uint64_t avg_; // Running average
void add(uint64_t value, size_t history_size);
};Node Reports
Aggregated metrics across the entire node:
cpp
auto report = app.get_state()->get_total_network_metrics();
// report.total_read_bytes()
// report.total_write_bytes()
// report.rtt_latency_ns_The node_report struct contains:
cpp
struct node_report {
uint64_t http_read_bytes_;
uint64_t http_write_bytes_;
uint64_t ws_read_bytes_;
uint64_t ws_write_bytes_;
uint64_t node_read_bytes_;
uint64_t node_write_bytes_;
std::array<opcode_report, 50> opcodes_; // snapshot of opcode counters
uint64_t mailbox_queue_size_;
uint64_t rtt_latency_ns_;
uint64_t total_read_bytes() const;
uint64_t total_write_bytes() const;
};opcode_report is the snapshot version of opcode_metrics — same fields, plain integers.
Metrics Collection Configuration
cpp
config.node_.metrics_interval_ms_.store(60000); // Aggregate and report every 60s
// Reset all metrics windows
app.get_state()->reset_metrics_window();Latency Tracking Configuration
cpp
config.latency_.enabled_.store(true);
config.latency_.interval_s_.store(5); // Measure every 5 seconds
config.latency_.timeout_s_.store(60); // Timeout after 60s
config.latency_.history_size_.store(10); // Keep last 10 readings