Overview
NanoARB exposes Prometheus metrics for comprehensive monitoring of trading performance, latency, and system health. The monitoring stack includes Prometheus for metrics collection and Grafana for visualization.Architecture
The monitoring stack consists of:- NanoARB Engine: Exposes metrics on port 9090
- Prometheus: Scrapes metrics every 1 second and stores time-series data
- Grafana: Provides real-time dashboards and alerting
Setup
Starting the Monitoring Stack
- With Docker Compose
- Standalone
Accessing Dashboards
Once the stack is running:- Grafana: http://localhost:3000
- Username:
admin - Password:
nanoarb
- Username:
- Prometheus: http://localhost:9091
- Metrics Endpoint: http://localhost:9090/metrics
Prometheus Configuration
The Prometheus configuration indocker/prometheus.yml:
The 1-second scrape interval is optimized for high-frequency trading. For longer-term monitoring, increase to 5s or 15s to reduce storage requirements.
- Default: 30 days (configured via
--storage.tsdb.retention.time=30d) - Adjust in docker-compose.yml if you need longer retention
Available Metrics
NanoARB exposes metrics in theMetricsRegistry defined in crates/nano-gateway/src/metrics.rs:
Trading Metrics
| Metric | Type | Description |
|---|---|---|
nanoarb_orders_total | Counter | Total number of orders submitted |
nanoarb_fills_total | Counter | Total number of fills received |
nanoarb_position | Gauge | Current net position in contracts |
nanoarb_pnl | Gauge | Current profit/loss in dollars |
nanoarb_events_total | Counter | Total events processed by the engine |
Latency Metrics
All latency metrics are recorded in nanoseconds with histogram buckets:| Metric | Type | Description |
|---|---|---|
nanoarb_inference_latency_ns | Histogram | ML model inference time |
nanoarb_order_latency_ns | Histogram | Order submission latency |
nanoarb_book_update_latency_ns | Histogram | Order book update processing time |
nanoarb_event_latency_ns | Histogram | Event processing latency |
- Range: 100ns to ~100ms
- Exponential buckets with factor of 2 (20 buckets total)
- Enables percentile queries (p50, p95, p99)
Example Queries
Grafana Dashboards
The default dashboard is located atgrafana/dashboards/main.json and includes:
1. Key Performance Indicators (Top Row)
P&L
Current profit/loss in dollars
Position
Current net position
Orders/min
Order submission rate
Fills/min
Fill execution rate
2. Equity Curve
Real-time visualization of cumulative P&L:3. Inference Latency
Tracks ML model performance with percentiles:- p50 (median): Typical inference time
- p95: 95th percentile - most requests complete within this time
- p99: 99th percentile - worst-case latency for optimization
4. Position Over Time
Tracks position changes throughout the trading session:- Identifying position accumulation
- Monitoring inventory risk
- Verifying position flattening at session end
5. Event Processing Rate
Monitors system throughput:- Heavy market data processing
- Potential bottlenecks in event loop
- Need for performance optimization
Dashboard Configuration
The dashboard is provisioned automatically ingrafana/provisioning/:
Adding Custom Panels
- Navigate to Grafana: http://localhost:3000
- Open Dashboard: “NanoARB Trading Dashboard”
- Add Panel: Click “Add panel” in top-right
- Configure Query: Use Prometheus queries from examples above
- Save Dashboard: Exports to JSON for version control
Custom Dashboard Example
Sharpe Ratio Panel
Sharpe Ratio Panel
Alerting
Configure Grafana Alerts
Example Alert Rules
High Latency Alert
High Latency Alert
Alert when p99 inference latency exceeds 10 microseconds:
Position Limit Alert
Position Limit Alert
Alert when position exceeds 80% of max:
Drawdown Alert
Drawdown Alert
Alert on significant drawdown (requires additional calculation):
Metrics Export
Raw Metrics Format
View raw Prometheus metrics:Export to CSV
Use Prometheus API to export historical data:Performance Monitoring
Key Metrics to Watch
Inference Latency
Target: <1μs p99Critical for strategy competitiveness
Order Latency
Target: <100μs p99Impacts fill probability
Event Processing Rate
Target: >50k events/secIndicates system capacity
Fill Ratio
Target: >80%Measures execution quality
Latency Optimization
If latencies are too high:- Check CPU pinning: Ensure process runs on isolated cores
- Review event loop: Look for blocking operations
- Profile code: Use
perforflamegraphto identify hotspots - Optimize model: Reduce inference complexity