Files
aiops/agent/model/model.go
T
attacker 2e71371257 feat: Phase 2-5 监控中心全栈实现 — 指标浏览器/SNMP/站点拨测/中间件
Phase 2 指标监控:
- 修复 /metrics 路由(原指向 AlertManager → 现指向 MetricsExplorer)
- 新建 MetricsHandler (4 API): targets/list/query/names
- 新建 MetricsExplorer 前端(170行): 目标选择器+指标分类树+多指标叠加SVG图表

Phase 3 SNMP设备:
- 新建 SNMPHandler (9 API): devices CRUD/templates/stats
- SNMPMonitor 接入真实API(428行): 设备表格+添加对话框+删除

Phase 4 站点拨测:
- 新建 SiteHandler (8 API): tasks CRUD/results/stats
- SiteMonitor 接入真实API(542行): 任务表+添加对话框+拨测类型网格
- 新增 siteApi 到 api.ts

Phase 5 中间件采集:
- Agent 新增 collector/middleware.go: Redis INFO + MySQL handshake 采集
- Agent CLI 新增 -redis/-redis-auth/-mysql/-mysql-user/-mysql-pass
- MiddlewareMonitor 接入真实API(301行): 实例卡片+指标面板

基础设施:
- AutoMigrate 新增 23 张监控表
- 前后端容器构建部署验证通过
2026-06-18 13:02:19 +00:00

82 lines
3.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package model 定义 AIOps Agent 与后端之间交互的数据结构。
// 这些结构经 JSON 序列化后上报至后端 /api/v1/agent/report 接口。
//
// 署名 Logan.Li
package model
// Report 为单次采集周期的完整上报报文
type Report struct {
Hostname string `json:"hostname"` // 主机名
Timestamp string `json:"timestamp"` // RFC3339 格式的 UTC 时间戳
CPU CPUStat `json:"cpu"` // CPU 指标
Memory MemoryStat `json:"memory"` // 内存指标
Disks []DiskStat `json:"disks"` // 磁盘指标列表
Ports []PortStat `json:"ports"` // 监听端口列表
Network NetworkStat `json:"network"` // 网络指标
DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO 指标
Middleware MiddlewareStat `json:"middleware,omitempty"` // 中间件指标(Redis/MySQL)
}
// MiddlewareStat 中间件综合指标 — 包含 Redis + MySQL
type MiddlewareStat struct {
Redis []RedisMetric `json:"redis,omitempty"` // Redis 实例指标
MySQL []MySQLMetric `json:"mysql,omitempty"` // MySQL 实例指标
}
// RedisMetric Redis 实例采集指标
type RedisMetric struct {
Instance string `json:"instance"` // 实例标识(host:port)
Clients int `json:"clients"` // 连接客户端数
UsedMemory int64 `json:"used_memory"` // 已用内存(字节)
HitRate float64 `json:"hit_rate"` // 缓存命中率(%)
QPS float64 `json:"qps"` // 每秒命令数
Uptime int64 `json:"uptime"` // 运行时长(秒)
Version string `json:"version"` // Redis 版本
}
// MySQLMetric MySQL 实例采集指标
type MySQLMetric struct {
Instance string `json:"instance"` // 实例标识(host:port)
Connections int `json:"connections"` // 当前连接数
QPS float64 `json:"qps"` // 每秒查询数
SlowQueries int64 `json:"slow_queries"` // 慢查询累计数
BufferHitRate float64 `json:"buffer_hit_rate"` // 缓冲池命中率(%)
ThreadsRunning int `json:"threads_running"` // 活跃线程数
Uptime int64 `json:"uptime"` // 运行时长(秒)
Version string `json:"version"` // MySQL 版本
}
// CPUStat CPU 相关指标
type CPUStat struct {
UsagePercent float64 `json:"usage_percent"` // CPU 总体使用率(百分比)
CoreCount int `json:"core_count"` // CPU 逻辑核心数
Load1 float64 `json:"load1"` // 1 分钟平均负载
Load5 float64 `json:"load5"` // 5 分钟平均负载
Load15 float64 `json:"load15"` // 15 分钟平均负载
}
// MemoryStat 内存相关指标
type MemoryStat struct {
TotalGB float64 `json:"total_gb"` // 总内存(GB)
UsedGB float64 `json:"used_gb"` // 已用内存(GB)
CachedGB float64 `json:"cached_gb"` // 缓存(Buffers + Cached,GB)
UsagePercent float64 `json:"usage_percent"` // 内存使用率(百分比)
}
// DiskStat 单个挂载点的磁盘使用情况
type DiskStat struct {
Mount string `json:"mount"` // 挂载点
Device string `json:"device"` // 设备名
TotalGB float64 `json:"total_gb"` // 总容量(GB)
UsedGB float64 `json:"used_gb"` // 已用容量(GB)
UsagePercent float64 `json:"usage_percent"` // 使用率(百分比)
}
// PortStat 监听端口及其归属进程
type PortStat struct {
Port int `json:"port"` // 监听端口
Protocol string `json:"protocol"` // 协议:tcp / tcp6
Process string `json:"process"` // 进程名(可执行文件名)
PID int `json:"pid"` // 进程 PID(无法解析时为 0)
}