feat: v0.34 健康探针(Architecture B) + Agent v2.1 + 端口监控 + 告警联系人重构
- v0.31: AlertContact 重构(channel_type下拉+webhook_url替代三分立字段) - v0.32: Agent ProcessTop 增强(cmdline/user/cpu_pct/mem_pct) - v0.33: 端口监控 Tab(监听端口自动发现+down联动告警) - v0.34: 健康探针(Agent本地执行HTTP/TCP/Exec→结果随心跳上报) - Agent新增: ContextSwitch/FD/HealthProbe采集器 - 后端新增: health_probe handler + Agent model扩展 - HostMonitor新增Tab: 健康探针/端口监控
This commit is contained in:
1 parent
e1f75f0bc4
commit
d656520428
25 files changed
+1700
-619
No files matched your search
@@ -353,3 +353,73 @@ type HostGroup struct {
|
||||
func (HostGroup) TableName() string {
|
||||
return "asset_host_groups"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// HealthProbe 健康探针配置(Agent 本地执行)
|
||||
// ============================================
|
||||
|
||||
// ProbeType 探针类型
|
||||
type ProbeType string
|
||||
|
||||
const (
|
||||
ProbeTypeHTTP ProbeType = "http_get" // HTTP GET 探测
|
||||
ProbeTypeTCP ProbeType = "tcp_socket" // TCP 端口连接探测
|
||||
ProbeTypeExec ProbeType = "exec_command" // 命令执行探测
|
||||
)
|
||||
|
||||
// ProbeStatus 探针结果状态
|
||||
type ProbeStatus string
|
||||
|
||||
const (
|
||||
ProbeStatusUp ProbeStatus = "up" // 健康
|
||||
ProbeStatusDown ProbeStatus = "down" // 异常
|
||||
)
|
||||
|
||||
// HealthProbe 健康探针配置表
|
||||
// 存储在平台 DB,Agent 拉取配置后在目标主机本地执行,结果随心跳上报
|
||||
type HealthProbe struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;index" json:"name"`
|
||||
Hostname string `gorm:"type:varchar(255);index;not null" json:"hostname"`
|
||||
ProbeType ProbeType `gorm:"type:varchar(32);not null" json:"probe_type"`
|
||||
// HTTP 探针配置
|
||||
HTTPURL string `gorm:"type:varchar(512)" json:"http_url,omitempty"`
|
||||
HTTPMethod string `gorm:"type:varchar(10);default:GET" json:"http_method,omitempty"`
|
||||
HTTPHeaders string `gorm:"type:text" json:"http_headers,omitempty"`
|
||||
HTTPExpectCode int `gorm:"default:200" json:"http_expect_code,omitempty"`
|
||||
HTTPExpectBody string `gorm:"type:varchar(256)" json:"http_expect_body,omitempty"`
|
||||
// TCP 探针配置
|
||||
TCPHost string `gorm:"type:varchar(255)" json:"tcp_host,omitempty"`
|
||||
TCPPort int `json:"tcp_port,omitempty"`
|
||||
// Exec 探针配置
|
||||
ExecCommand string `gorm:"type:text" json:"exec_command,omitempty"`
|
||||
// 通用配置
|
||||
Timeout int `gorm:"default:10" json:"timeout"`
|
||||
Interval int `gorm:"default:60" json:"interval"`
|
||||
Enabled bool `gorm:"default:true;index" json:"enabled"`
|
||||
LastStatus ProbeStatus `gorm:"type:varchar(8);default:''" json:"last_status,omitempty"`
|
||||
LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
|
||||
LastLatencyMs int `json:"last_latency_ms"`
|
||||
FailCount int `json:"fail_count"`
|
||||
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (HealthProbe) TableName() string {
|
||||
return "monitor_health_probes"
|
||||
}
|
||||
|
||||
// HealthProbeResult Agent 上报的探针执行结果(作为心跳的一部分)
|
||||
type HealthProbeResult struct {
|
||||
ProbeID uint `json:"probe_id"`
|
||||
Name string `json:"name"`
|
||||
ProbeType string `json:"probe_type"`
|
||||
Status ProbeStatus `json:"status"` // up / down
|
||||
LatencyMs int `json:"latency_ms"` // 响应延迟(ms)
|
||||
StatusCode int `json:"status_code,omitempty"` // HTTP 状态码
|
||||
Message string `json:"message,omitempty"` // 错误/附加信息
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user