Skip to main content

Crate trojan_metrics

Crate trojan_metrics 

Source
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_prometheusDeprecated
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.