Files
aiops/agent/model/model_ext.go
T
attacker ad714c49f1 refactor(agent): 简化CLI——去掉-p/-D flag,改用子命令 output/discover
- ./aiops-agent output  → Zabbix风格输出全部上报指标(与API一致,含Heartbeat)
- ./aiops-agent discover → Zabbix LLD端口发现JSON
- ./aiops-agent -server URL → 正常采集模式(不变)
- runOutput 构建与 collectAndReport 完全相同的 Report 结构体
- 新增 net.tcp.close_wait 采集(解析/proc/net/tcp state=08)
- 静态编译 (CGO_ENABLED=0) 兼容 Alpine 容器
2026-06-24 14:01:52 +00:00

88 lines
3.5 KiB
Go

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)
}
// 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)
}
// 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"`
}