Trojan Rust

Prometheus Metrics

Monitoring trojan-rs with Prometheus metrics

trojan-rs exposes Prometheus metrics via an HTTP endpoint when configured.

Setup

[metrics]
listen = "127.0.0.1:9100"

This starts an HTTP server with three endpoints:

EndpointDescription
/metricsPrometheus metrics in text exposition format
/healthHealth check (returns 200 OK)
/readyReadiness check (returns 200 OK)

Available Metrics

Connection Metrics

MetricTypeDescription
trojan_connections_totalCounterTotal connections accepted
trojan_connections_activeGaugeCurrently active connections
trojan_connections_tcpCounterTCP CONNECT requests
trojan_connections_udpCounterUDP ASSOCIATE requests
trojan_connections_fallbackCounterConnections forwarded to fallback

Authentication Metrics

MetricTypeDescription
trojan_auth_success_totalCounterSuccessful authentications
trojan_auth_failure_totalCounterFailed authentications
trojan_auth_reload_totalCounterAuth database reloads

Traffic Metrics

MetricTypeDescription
trojan_bytes_upload_totalCounterTotal bytes uploaded (client → target)
trojan_bytes_download_totalCounterTotal bytes downloaded (target → client)
trojan_udp_packets_totalCounterTotal UDP packets relayed

Error Metrics

MetricTypeDescription
trojan_errors_totalCounterTotal errors by type
trojan_tls_handshake_failuresCounterTLS handshake failures
trojan_header_parse_errorsCounterTrojan header parse errors

Performance Metrics

MetricTypeDescription
trojan_connection_duration_secondsHistogramConnection lifetime duration
trojan_tls_handshake_duration_secondsHistogramTLS handshake duration

Rate Limiting Metrics

MetricTypeDescription
trojan_rate_limited_totalCounterConnections rejected by rate limiter

WebSocket Metrics

MetricTypeDescription
trojan_websocket_connections_totalCounterWebSocket connections
trojan_websocket_upgrade_failuresCounterFailed WebSocket upgrades

Prometheus Configuration

Add a scrape target in prometheus.yml:

scrape_configs:
  - job_name: 'trojan'
    static_configs:
      - targets: ['127.0.0.1:9100']
    scrape_interval: 15s

Grafana Dashboard

Example panels for a Grafana dashboard:

Active Connections

trojan_connections_active

Connection Rate (per second)

rate(trojan_connections_total[5m])

Traffic Rate

rate(trojan_bytes_download_total[5m])
rate(trojan_bytes_upload_total[5m])

Auth Failure Rate

rate(trojan_auth_failure_total[5m])

P99 Connection Duration

histogram_quantile(0.99, rate(trojan_connection_duration_seconds_bucket[5m]))

On this page