Expand description
Metrics collection and Prometheus exporter for trojan-rs.
This module provides metrics instrumentation for the trojan server, including connection counts, bytes transferred, and error rates.
Constants§
- AUTH_
FAILURE_ BY_ COUNTRY - Total auth failures by source country.
- AUTH_
FAILURE_ TOTAL - Total number of failed authentications.
- AUTH_
SUCCESS_ TOTAL - Total number of successful authentications.
- BYTES_
BY_ COUNTRY - Total bytes by source country and direction.
- BYTES_
RECEIVED_ TOTAL - Total bytes received from clients.
- BYTES_
SENT_ TOTAL - Total bytes sent to clients.
- CONNECTIONS_
ACTIVE - Number of currently active connections.
- CONNECTIONS_
BY_ COUNTRY - Total connections by source country.
- CONNECTIONS_
REJECTED_ TOTAL - Total number of connections rejected (rate limit, max connections).
- CONNECTIONS_
TOTAL - Total number of TCP connections accepted.
- CONNECTION_
DURATION_ SECONDS - Connection duration histogram (seconds).
- CONNECTION_
QUEUE_ DEPTH - Connection queue depth (pending connections in accept backlog).
- CONNECT_
REQUESTS_ TOTAL - Total number of CONNECT requests.
- DNS_
RESOLVE_ DURATION_ SECONDS - DNS resolution duration histogram (seconds).
- ERRORS_
TOTAL - Total number of errors by type.
- ERROR_
AUTH - Authentication error.
- ERROR_
CONFIG - Configuration error.
- ERROR_
IO - I/O error.
- ERROR_
PROTOCOL - Protocol parsing/validation error.
- ERROR_
RESOLVE - DNS/address resolution error.
- ERROR_
TIMEOUT - Timeout error.
- ERROR_
TLS_ HANDSHAKE - TLS handshake error.
- FALLBACK_
POOL_ SIZE - Current size of the fallback warm pool.
- FALLBACK_
POOL_ WARM_ FAIL_ TOTAL - Total number of warm-fill connection failures.
- FALLBACK_
TOTAL - Total number of fallback connections (non-trojan traffic).
- RULE_
UPDATES_ TOTAL - Total number of successful rule engine updates (hot-reload).
- RULE_
UPDATE_ ERRORS_ TOTAL - Total number of failed rule engine update attempts (hot-reload).
- TARGET_
BYTES_ TOTAL - Per-target bytes transferred.
- TARGET_
CONNECTIONS_ TOTAL - Per-target connection counts (by destination).
- TARGET_
CONNECT_ DURATION_ SECONDS - Target connection establishment duration histogram (seconds).
- TLS_
HANDSHAKE_ DURATION_ SECONDS - TLS handshake duration histogram (seconds).
- UDP_
ASSOCIATE_ REQUESTS_ TOTAL - Total number of UDP associate requests.
- UDP_
PACKETS_ TOTAL - Total number of UDP packets relayed.
Functions§
- init_
metrics_ server - Initialize metrics server with Prometheus exporter and health check endpoints.
- init_
prometheus Deprecated - Initialize Prometheus metrics exporter (legacy function).
- record_
auth_ failure - Record failed authentication (triggers fallback).
- record_
auth_ failure_ with_ geo - Record an authentication failure with source country label.
- record_
auth_ success - Record successful authentication.
- record_
bytes_ received - Record bytes received from client.
- record_
bytes_ sent - Record bytes sent to client.
- record_
bytes_ with_ geo - Record bytes transferred with source country label. Direction: “sent” or “received”.
- record_
connect_ request - Record a CONNECT request.
- record_
connection_ accepted - Record a new connection accepted.
- record_
connection_ closed - Record a connection closed.
- record_
connection_ rejected - Record a rejected connection (reason: “max_connections”, “rate_limit”).
- record_
connection_ with_ geo - Record a connection with source country label.
- record_
dns_ resolve_ duration - Record DNS resolution duration.
- record_
error - Record an error by type.
- record_
fallback - Record fallback to HTTP backend.
- record_
fallback_ pool_ warm_ fail - Record warm-fill connection failure.
- record_
rule_ update - Record a successful rule engine update (hot-reload).
- record_
rule_ update_ error - Record a failed rule engine update attempt (hot-reload).
- record_
target_ bytes - Record bytes transferred to/from a target. Direction: “sent” or “received”. Note: This function allocates a String for the label. For hot paths with repeated calls, consider caching the String at the call site.
- record_
target_ connect_ duration - Record target connection establishment duration.
- record_
target_ connection - Record a connection to a target (by destination host). The target should be sanitized (e.g., IP address or domain without port). Note: This function allocates a String for the label. For hot paths with repeated calls, consider caching the String at the call site.
- record_
tls_ handshake_ duration - Record TLS handshake duration.
- record_
udp_ associate_ request - Record a UDP associate request.
- record_
udp_ packet - Record UDP packets relayed (direction: “inbound” or “outbound”).
- set_
connection_ queue_ depth - Set connection queue depth gauge.
- set_
fallback_ pool_ size - Set current fallback pool size.