Skip to main content

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

Accessing Dashboards

Once the stack is running:

Prometheus Configuration

The Prometheus configuration in docker/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.
Data retention:
  • 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 the MetricsRegistry defined in crates/nano-gateway/src/metrics.rs:

Trading Metrics

Latency Metrics

All latency metrics are recorded in nanoseconds with histogram buckets: Histogram buckets:
  • 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 at grafana/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:
Shows your trading performance over time, helping identify profitable and unprofitable periods.

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
For HFT strategies, target p99 inference latency under 1 microsecond (1000ns). Higher latencies may result in adverse selection.

4. Position Over Time

Tracks position changes throughout the trading session:
Useful for:
  • Identifying position accumulation
  • Monitoring inventory risk
  • Verifying position flattening at session end

5. Event Processing Rate

Monitors system throughput:
High event rates (>10,000 events/sec) indicate:
  • Heavy market data processing
  • Potential bottlenecks in event loop
  • Need for performance optimization

Dashboard Configuration

The dashboard is provisioned automatically in grafana/provisioning/:

Adding Custom Panels

  1. Navigate to Grafana: http://localhost:3000
  2. Open Dashboard: “NanoARB Trading Dashboard”
  3. Add Panel: Click “Add panel” in top-right
  4. Configure Query: Use Prometheus queries from examples above
  5. Save Dashboard: Exports to JSON for version control

Custom Dashboard Example

Calculates rolling Sharpe ratio based on P&L standard deviation.

Alerting

Configure Grafana Alerts

1

Create Alert Rule

In Grafana, go to AlertingAlert rulesNew alert rule
2

Define Condition

Example: Alert when P&L drops below -$10,000
3

Configure Notification

Set up notification channels (Slack, email, PagerDuty)
4

Save and Test

Test the alert and save the configuration

Example Alert Rules

Alert when p99 inference latency exceeds 10 microseconds:
Alert when position exceeds 80% of max:
Alert on significant drawdown (requires additional calculation):

Metrics Export

Raw Metrics Format

View raw Prometheus metrics:
Example output:

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:
  1. Check CPU pinning: Ensure process runs on isolated cores
  2. Review event loop: Look for blocking operations
  3. Profile code: Use perf or flamegraph to identify hotspots
  4. Optimize model: Reduce inference complexity
See Production Deployment for optimization techniques.

Troubleshooting

Metrics Not Appearing

Dashboard Not Loading

High Memory Usage

Prometheus stores metrics in memory. Reduce retention or scrape interval:

Next Steps

Docker

Docker deployment guide

Production

Production optimization and best practices