Expand description
Analytics module for trojan-rs.
This module provides detailed connection event collection and export to ClickHouse for traffic analysis, billing, and auditing.
§Feature Gating
This crate should be used with the analytics feature in trojan-server:
[features]
analytics = ["trojan-analytics"]§Example
ⓘ
use trojan_analytics::{EventCollector, init};
use trojan_config::AnalyticsConfig;
// Initialize analytics
let collector = init(config).await?;
// Record connection events
let event = collector.connection(conn_id, peer)
.user("user123")
.target("example.com", 443, TargetType::Domain)
.protocol(Protocol::Tcp);
// Event is automatically sent on dropStructs§
- Analytics
Buffer Config - Buffer configuration for event batching.
- Analytics
Config - Analytics configuration for connection event collection.
- Analytics
Privacy Config - Privacy configuration for data collection.
- Analytics
Sampling Config - Sampling configuration for high-traffic scenarios.
- Click
House Config - ClickHouse connection configuration.
- Connection
Event - A connection event representing the full lifecycle of a single connection.
- Connection
Event Builder - Builder for constructing connection events.
- Event
Collector - Event collector for recording connection events.
Enums§
- Analytics
Error - Analytics module errors.
- Auth
Result - Authentication result.
- Close
Reason - Connection close reason.
- Protocol
- Connection protocol.
- Target
Type - Target address type.
- Transport
- Transport layer type.
Functions§
- init
- Initialize the analytics module.