Documentation
¶
Index ¶
- Variables
- type Config
- type Metrics
- type Option
- type ProtocolManager
- func (pm *ProtocolManager) AddProtocol(p *protocols.Protocol)
- func (pm *ProtocolManager) Close()
- func (pm *ProtocolManager) GetMetrics() map[string]interface{}
- func (pm *ProtocolManager) GetProtocols() []*protocols.Protocol
- func (pm *ProtocolManager) RemoveProtocol(name string)
- func (pm *ProtocolManager) RunServer(ctx context.Context, address string) error
- func (pm *ProtocolManager) UpdateProtocol(name string, newProtocol *protocols.Protocol)
- type ProtocolTrafficStats
- type TrafficCounter
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = Config{ MaxConnections: 1024, BufferSize: 32 * 1024, IdentifyTimeout: 15 * time.Second, CacheTTL: 5 * time.Minute, DialTimeout: 5 * time.Second, }
DefaultConfig 默认配置
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
MaxConnections int // 最大并发连接数
BufferSize int // 缓冲区大小
IdentifyTimeout time.Duration // 协议识别超时时间
CacheTTL time.Duration // 缓存过期时间
DialTimeout time.Duration // 连接目标服务器超时时间
}
Config 配置结构
type Metrics ¶
type Metrics struct {
ActiveConnections atomic.Int64
ProtocolHits sync.Map // map[string]int64
IdentifyErrors atomic.Int64
ProxyErrors atomic.Int64
CurrentInBytes atomic.Int64 // 当前入站速率 (bytes/s)
CurrentOutBytes atomic.Int64 // 当前出站速率 (bytes/s)
TotalInBytes atomic.Int64 // 总入站流量
TotalOutBytes atomic.Int64 // 总出站流量
LastInBytes atomic.Int64 // 上一秒入站流量
LastOutBytes atomic.Int64 // 上一秒出站流量
// 新增按协议统计的流量指标
ProtocolTraffic sync.Map // map[string]*ProtocolTrafficStats
}
Metrics 指标结构
type Option ¶
type Option func(*Config)
Option 定义配置选项的函数类型
func WithIdentifyTimeout ¶
WithIdentifyTimeout 设置协议识别超时时间
type ProtocolManager ¶
type ProtocolManager struct {
// contains filtered or unexported fields
}
ProtocolManager 管理协议列表
func NewProtocolManager ¶
func NewProtocolManager(opts ...Option) *ProtocolManager
NewProtocolManager 创建一个新的 ProtocolManager
func (*ProtocolManager) AddProtocol ¶
func (pm *ProtocolManager) AddProtocol(p *protocols.Protocol)
AddProtocol 添加新协议
func (*ProtocolManager) Close ¶
func (pm *ProtocolManager) Close()
Close 关闭 ProtocolManager 及其所有后台任务
func (*ProtocolManager) GetMetrics ¶
func (pm *ProtocolManager) GetMetrics() map[string]interface{}
GetMetrics 获取当前指标
func (*ProtocolManager) GetProtocols ¶
func (pm *ProtocolManager) GetProtocols() []*protocols.Protocol
GetProtocols 获取当前的协议列表
func (*ProtocolManager) RemoveProtocol ¶
func (pm *ProtocolManager) RemoveProtocol(name string)
RemoveProtocol 移除指定名称的协议
func (*ProtocolManager) RunServer ¶
func (pm *ProtocolManager) RunServer(ctx context.Context, address string) error
RunServer 运行协议分流器
func (*ProtocolManager) UpdateProtocol ¶
func (pm *ProtocolManager) UpdateProtocol(name string, newProtocol *protocols.Protocol)
UpdateProtocol 更新指定名称的协议
type ProtocolTrafficStats ¶
type ProtocolTrafficStats struct {
TotalIn atomic.Int64 // 协议总入站流量
TotalOut atomic.Int64 // 协议总出站流量
CurrentIn atomic.Int64 // 协议当前入站速率
CurrentOut atomic.Int64 // 协议当前出站速率
LastIn atomic.Int64 // 协议上一秒入站流量
LastOut atomic.Int64 // 协议上一秒出站流量
}
ProtocolTrafficStats 协议流量统计
type TrafficCounter ¶
type TrafficCounter struct {
// contains filtered or unexported fields
}
TrafficCounter 流量计数器
Click to show internal directories.
Click to hide internal directories.