monitor

package
v0.0.0-...-69fac63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveClients = &ActiveConnectionsManager{
	conns: make(map[string]*ClientConnection),
}

全局活跃客户端管理器

View Source
var GlobalTrafficStats = &TrafficStats{
	ProxyGroupStats: make(map[string]*ProxyGroupTraffic),
	LastUpdate:      time.Now(),
	PrevNetCounters: make(map[string]net.IOCountersStat),
}

Functions

func FormatBytes

func FormatBytes(b uint64) string

字节格式化

func FormatBytesPerSec

func FormatBytesPerSec(bytes uint64, _ uint64) string

带宽格式化

func FormatNetworkBandwidth

func FormatNetworkBandwidth(bytes uint64) string

网络流量带宽格式化

func GetClientIP

func GetClientIP(r *http.Request) string

func HandleMonitor

func HandleMonitor(w http.ResponseWriter, r *http.Request)

HTTP 处理入口

func StartSystemStatsUpdater

func StartSystemStatsUpdater(interval time.Duration, stopChan chan struct{})

Types

type ActiveConnectionsManager

type ActiveConnectionsManager struct {
	// contains filtered or unexported fields
}

ActiveConnectionsManager 管理活跃客户端

func (*ActiveConnectionsManager) CleanInactiveConnections

func (m *ActiveConnectionsManager) CleanInactiveConnections(timeout time.Duration)

CleanInactiveConnections 清理不活跃连接

func (*ActiveConnectionsManager) GetAll

GetAll 获取所有活跃客户端连接

func (*ActiveConnectionsManager) GetConnectionByID

func (m *ActiveConnectionsManager) GetConnectionByID(connID string) *ClientConnection

GetConnectionByID 根据 ConnID 获取单个客户端连接

func (*ActiveConnectionsManager) GetConnectionsByIP

func (m *ActiveConnectionsManager) GetConnectionsByIP(ip string) []*ClientConnection

GetConnectionsByIP 获取指定IP的所有连接

func (*ActiveConnectionsManager) Register

func (m *ActiveConnectionsManager) Register(connID string, conn *ClientConnection)

Register 注册客户端连接

func (*ActiveConnectionsManager) StartCleaner

func (m *ActiveConnectionsManager) StartCleaner(interval time.Duration, timeout time.Duration, stopChan chan struct{})

StartCleaner 启动定时清理器

func (*ActiveConnectionsManager) Unregister

func (m *ActiveConnectionsManager) Unregister(connID string, connType string)

Unregister 注销客户端连接

func (*ActiveConnectionsManager) UpdateLastActive

func (m *ActiveConnectionsManager) UpdateLastActive(connID string, t time.Time)

UpdateLastActive 更新客户端最后活跃时间

type AppStats

type AppStats struct {
	CPUPercent        float64
	MemoryUsage       uint64
	TotalBytes        uint64
	InboundBytes      uint64
	OutboundBytes     uint64
	InboundBandwidth  uint64
	OutboundBandwidth uint64
	LastUpdate        time.Time
	PrevIOCounters    *process.IOCountersStat
	PrevCPUTime       float64 // ← 新增,用于计算 CPU 百分比
	CPUTemperature    float64 // 添加CPU温度字段
}

type ClientConnection

type ClientConnection struct {
	ID             string
	IP             string
	URL            string
	UserAgent      string
	Referer        string
	ConnectionType string // RTSP/HTTP/UDP/HTTPS
	IsMobile       bool
	ConnectedAt    time.Time
	LastActive     time.Time
}

ClientConnection 表示一个客户端连接

type DiskPartitionInfo

type DiskPartitionInfo struct {
	Path        string
	Total       uint64
	Used        uint64
	Free        uint64
	UsedPercent float64
	FsType      string
	MountPoint  string
}

type HostInfo

type HostInfo struct {
	OS            string
	Platform      string
	KernelArch    string
	KernelVersion string
}

type LoadAverageInfo

type LoadAverageInfo struct {
	Load1  float64
	Load5  float64
	Load15 float64
}

type NetworkInterfaceInfo

type NetworkInterfaceInfo struct {
	Name          string
	BytesRecv     uint64
	BytesSent     uint64
	PacketsRecv   uint64
	PacketsSent   uint64
	RecvBandwidth uint64 // 实时接收带宽 (bytes/sec)
	SendBandwidth uint64 // 实时发送带宽 (bytes/sec)
}

type ProxyGroupTraffic

type ProxyGroupTraffic struct {
	GroupName        string
	Connections      int64
	BytesTransferred int64
	ActiveStreams    int64
	LastError        string
	LastActivity     time.Time
}

type StatusData

type StatusData struct {
	Timestamp     time.Time
	Uptime        time.Duration
	Version       string
	Goroutines    int
	MemoryStats   runtime.MemStats
	ProxyGroups   map[string]*config.ProxyGroupConfig
	TrafficStats  *TrafficStats
	ClientIP      string
	ActiveClients []*ClientConnection
	WebPath       string
}

页面数据结构

type TrafficStats

type TrafficStats struct {
	// 系统
	TotalConnections  int64
	ActiveConnections int64
	TotalBytes        uint64

	InboundBytes      uint64
	OutboundBytes     uint64
	InboundBandwidth  uint64
	OutboundBandwidth uint64

	CPUUsage        float64
	CPUCount        int
	MemoryUsage     uint64
	MemoryTotal     uint64
	SwapUsage       uint64 // SWAP使用量
	SwapTotal       uint64 // SWAP总量
	DiskUsage       uint64
	DiskTotal       uint64
	DiskUsedPercent float64
	DiskPartitions  []DiskPartitionInfo
	CPUTemperature  float64 // 添加CPU温度字段

	LoadAverage LoadAverageInfo
	HostInfo    HostInfo

	NetworkInterfaces []NetworkInterfaceInfo

	ProxyGroupStats map[string]*ProxyGroupTraffic

	// 应用自身流量
	App AppStats

	LastUpdate      time.Time
	PrevNetCounters map[string]net.IOCountersStat
	// contains filtered or unexported fields
}

func (*TrafficStats) GetTrafficStats

func (ts *TrafficStats) GetTrafficStats() *TrafficStats

GetTrafficStats 获取流量统计信息的深拷贝

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL