package model // NetworkStat 网络相关指标 type NetworkStat struct { TCPEstablished int `json:"tcp_established"` // ESTABLISHED 连接数 TCPTimeWait int `json:"tcp_time_wait"` // TIME_WAIT 连接数 TCPCloseWait int `json:"tcp_close_wait"` // CLOSE_WAIT 连接数 TCPTotal int `json:"tcp_total"` // TCP 总连接数 NicName string `json:"nic_name"` // 主网卡名 NetRxBPS float64 `json:"net_rx_bps"` // 网卡接收速率 (bytes/s) NetTxBPS float64 `json:"net_tx_bps"` // 网卡发送速率 (bytes/s) NetRxErrors int64 `json:"net_rx_errors"` // 网卡接收错误包累计 — 物理层故障告警 NetTxErrors int64 `json:"net_tx_errors"` // 网卡发送错误包累计 — 物理层故障告警 } // DiskIOStat 磁盘 IO 相关指标 type DiskIOStat struct { ReadBPS float64 `json:"read_bps"` // 读取速率 (bytes/s) WriteBPS float64 `json:"write_bps"` // 写入速率 (bytes/s) ReadIOPS float64 `json:"read_iops"` // 读取 IOPS (count/s) WriteIOPS float64 `json:"write_iops"` // 写入 IOPS (count/s) Util float64 `json:"util"` // 磁盘繁忙程度(百分比)— 判断磁盘是否瓶颈的核心指标 } // SwapStat 交换分区指标(OOM 前兆判断) type SwapStat struct { TotalGB float64 `json:"total_gb"` UsedGB float64 `json:"used_gb"` UsagePercent float64 `json:"usage_percent"` } // SocketFDStat 系统级 FD 使用情况 type SocketFDStat struct { Allocated int `json:"allocated"` // 已分配的 file handles (fs.file-nr 第一列) Max int64 `json:"max"` // 系统上限 (fs.file-max) UsagePct float64 `json:"usage_pct"` } // ContextSwitchStat 上下文切换(决定是否开中断合并/CPU 隔离) type ContextSwitchStat struct { CTXPerSec float64 `json:"ctx_per_sec"` // 每秒上下文切换次数 IRQPerSec float64 `json:"irq_per_sec"` // 每秒中断次数 } // AgentHeartbeat Agent 自检心跳(随每次上报附带,极小 payload) type AgentHeartbeat struct { Version string `json:"version"` UptimeSec int64 `json:"uptime_sec"` LastErr string `json:"last_err,omitempty"` SelfCPU float64 `json:"self_cpu_pct"` SelfRSSMB float64 `json:"self_rss_mb"` ReportSeq uint64 `json:"report_seq"` // 单调递增序列号,用于丢包检测 } // SystemStat 系统信息(启动时采集一次) type SystemStat struct { OSVersion string `json:"os_version"` // OS 版本 (如 "Ubuntu 22.04") Kernel string `json:"kernel"` // 内核版本 Uptime int64 `json:"uptime"` // 运行秒数 UlimitNofile int64 `json:"ulimit_nofile"` // ulimit -n (最大文件描述符) UlimitNproc int64 `json:"ulimit_nproc"` // ulimit -u (最大进程数) } // ──── v2.1 健康探针 ──── // ProbeConfig 后端下发的探针配置 type ProbeConfig struct { ID uint `json:"id"` Name string `json:"name"` ProbeType string `json:"probe_type"` // http_get / tcp_socket / exec_command HTTPURL string `json:"http_url,omitempty"` HTTPMethod string `json:"http_method,omitempty"` HTTPExpectCode int `json:"http_expect_code,omitempty"` HTTPExpectBody string `json:"http_expect_body,omitempty"` TCPHost string `json:"tcp_host,omitempty"` TCPPort int `json:"tcp_port,omitempty"` ExecCommand string `json:"exec_command,omitempty"` Timeout int `json:"timeout"` } // ProbeResult 探针执行结果 type ProbeResult struct { ProbeID uint `json:"probe_id"` Name string `json:"name"` ProbeType string `json:"probe_type"` Status string `json:"status"` // up / down LatencyMs int `json:"latency_ms"` StatusCode int `json:"status_code,omitempty"` Message string `json:"message,omitempty"` } // PortPolicy 后端下发的端口过滤策略 // Logan.Li type PortPolicy struct { Hostname string `json:"hostname"` PortFilterMode string `json:"port_filter_mode"` // whitelist / blacklist PortWhitelist []int `json:"port_whitelist"` // 端口号数组 } // IsBlacklistMode 判断是否为黑名单模式(只上报选中端口) func (p *PortPolicy) IsBlacklistMode() bool { return p.PortFilterMode == "blacklist" } // InWhitelist 检查端口是否在白名单中 func (p *PortPolicy) InWhitelist(port int) bool { for _, w := range p.PortWhitelist { if w == port { return true } } return false }