Prometheus Metrics
Monitoring trojan-rs with Prometheus metrics
trojan-rs exposes Prometheus metrics via an HTTP endpoint when configured.
[metrics]
listen = "127.0.0.1:9100"
This starts an HTTP server with three endpoints:
| Endpoint | Description |
|---|
/metrics | Prometheus metrics in text exposition format |
/health | Health check (returns 200 OK) |
/ready | Readiness check (returns 200 OK) |
| Metric | Type | Description |
|---|
trojan_connections_total | Counter | Total connections accepted |
trojan_connections_active | Gauge | Currently active connections |
trojan_connections_tcp | Counter | TCP CONNECT requests |
trojan_connections_udp | Counter | UDP ASSOCIATE requests |
trojan_connections_fallback | Counter | Connections forwarded to fallback |
| Metric | Type | Description |
|---|
trojan_auth_success_total | Counter | Successful authentications |
trojan_auth_failure_total | Counter | Failed authentications |
trojan_auth_reload_total | Counter | Auth database reloads |
| Metric | Type | Description |
|---|
trojan_bytes_upload_total | Counter | Total bytes uploaded (client → target) |
trojan_bytes_download_total | Counter | Total bytes downloaded (target → client) |
trojan_udp_packets_total | Counter | Total UDP packets relayed |
| Metric | Type | Description |
|---|
trojan_errors_total | Counter | Total errors by type |
trojan_tls_handshake_failures | Counter | TLS handshake failures |
trojan_header_parse_errors | Counter | Trojan header parse errors |
| Metric | Type | Description |
|---|
trojan_connection_duration_seconds | Histogram | Connection lifetime duration |
trojan_tls_handshake_duration_seconds | Histogram | TLS handshake duration |
| Metric | Type | Description |
|---|
trojan_rate_limited_total | Counter | Connections rejected by rate limiter |
| Metric | Type | Description |
|---|
trojan_websocket_connections_total | Counter | WebSocket connections |
trojan_websocket_upgrade_failures | Counter | Failed WebSocket upgrades |
Add a scrape target in prometheus.yml:
scrape_configs:
- job_name: 'trojan'
static_configs:
- targets: ['127.0.0.1:9100']
scrape_interval: 15s
Example panels for a Grafana dashboard:
trojan_connections_active
rate(trojan_connections_total[5m])
rate(trojan_bytes_download_total[5m])
rate(trojan_bytes_upload_total[5m])
rate(trojan_auth_failure_total[5m])
histogram_quantile(0.99, rate(trojan_connection_duration_seconds_bucket[5m]))