Skip to main content

Crate trojan_analytics

Crate trojan_analytics 

Source
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 drop

Structs§

AnalyticsBufferConfig
Buffer configuration for event batching.
AnalyticsConfig
Analytics configuration for connection event collection.
AnalyticsPrivacyConfig
Privacy configuration for data collection.
AnalyticsSamplingConfig
Sampling configuration for high-traffic scenarios.
ClickHouseConfig
ClickHouse connection configuration.
ConnectionEvent
A connection event representing the full lifecycle of a single connection.
ConnectionEventBuilder
Builder for constructing connection events.
EventCollector
Event collector for recording connection events.

Enums§

AnalyticsError
Analytics module errors.
AuthResult
Authentication result.
CloseReason
Connection close reason.
Protocol
Connection protocol.
TargetType
Target address type.
Transport
Transport layer type.

Functions§

init
Initialize the analytics module.