Documentation
¶
Index ¶
Constants ¶
View Source
const (
AppName = "nodes"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CleanMetricRequest ¶
type CleanMetricRequest struct {
BeforeHours int64 `json:"before_hours"` // 清理指定小时之前的数据,单位:小时
}
func NewCleanMetricRequest ¶
func NewCleanMetricRequest(beforeHours int64) *CleanMetricRequest
type CleanMetricResponse ¶
type CleanMetricResponse struct {
Deleted int64 `json:"deleted"`
}
type Node ¶
type Node struct {
Id string `gorm:"column:id;primary_key;type:varchar(100)" json:"id"`
NodeName string `gorm:"column:node_name;type:varchar(100);uniqueIndex" json:"node_name"` // 主键:主机名
NodeIP string `gorm:"column:node_ip;type:varchar(50)" json:"node_ip"` // 节点IP
NodePort int `gorm:"column:node_port;type:int" json:"node_port"` // 节点端口
Status NodeStatus `gorm:"column:status;type:varchar(20)" json:"status"` // online/offline
RegisterTime time.Time `gorm:"column:register_time;type:datetime" json:"register_time"` // 注册时间
LastSeen time.Time `gorm:"column:last_seen;type:datetime;index" json:"last_seen"` // 最后心跳时间
Version string `gorm:"column:version;type:varchar(50)" json:"version"` // 节点版本
BuildTime string `gorm:"column:build_time;type:varchar(100)" json:"build_time"` // 构建时间
Labels string `gorm:"column:labels;type:text" json:"labels"` // 节点标签(JSON)
}
Node 节点信息
type NodeMetric ¶
type NodeMetric struct {
Id int64 `gorm:"column:id;primary_key" json:"id"`
// Agent ID
AgentId string `gorm:"column:agent_id;type:varchar(100);index" json:"agent_id"`
// 上报时间
ReportTime time.Time `gorm:"column:report_time;type:datetime;index" json:"report_time"`
// CPU 指标
CPUUsagePercent float64 `gorm:"column:cpu_usage_percent;type:double" json:"cpu_usage_percent"` // CPU使用率 (%)
CPUCores int `gorm:"column:cpu_cores;type:int" json:"cpu_cores"` // CPU核心数
// 内存指标
MemoryUsedMB int64 `gorm:"column:memory_used_mb;type:bigint" json:"memory_used_mb"` // 已用内存 (MB)
MemoryTotalMB int64 `gorm:"column:memory_total_mb;type:bigint" json:"memory_total_mb"` // 总内存 (MB)
MemoryUsagePercent float64 `gorm:"column:memory_usage_percent;type:double" json:"memory_usage_percent"` // 内存使用率 (%)
// 磁盘指标
DiskUsedGB int64 `gorm:"column:disk_used_gb;type:bigint" json:"disk_used_gb"` // 已用磁盘 (GB)
DiskTotalGB int64 `gorm:"column:disk_total_gb;type:bigint" json:"disk_total_gb"` // 总磁盘 (GB)
DiskUsagePercent float64 `gorm:"column:disk_usage_percent;type:double" json:"disk_usage_percent"` // 磁盘使用率 (%)
// 负载指标
LoadAverage1 float64 `gorm:"column:load_average_1;type:double" json:"load_average_1"` // 1分钟平均负载
LoadAverage5 float64 `gorm:"column:load_average_5;type:double" json:"load_average_5"` // 5分钟平均负载
LoadAverage15 float64 `gorm:"column:load_average_15;type:double" json:"load_average_15"` // 15分钟平均负载
// 关键资源指标
ProcessCount int `gorm:"column:process_count;type:int" json:"process_count"` // 系统进程总数
InodeUsagePercent float64 `gorm:"column:inode_usage_percent;type:double" json:"inode_usage_percent"` // Inode 使用率 (%)
FileHandleUsagePercent float64 `gorm:"column:file_handle_usage_percent;type:double" json:"file_handle_usage_percent"` // 文件句柄使用率 (%)
// 任务执行指标
RunningTasks int `gorm:"column:running_tasks;type:int" json:"running_tasks"` // 正在运行的任务数
// Runtime 指标
GoroutineCount int `gorm:"column:goroutine_count;type:int" json:"goroutine_count"` // Goroutine数量
}
NodeMetric Agent 运行指标
func (*NodeMetric) TableName ¶
func (m *NodeMetric) TableName() string
type NodeStatus ¶
type NodeStatus string
NodeStatus 节点状态
const ( NODE_STATUS_ONLINE NodeStatus = "online" // 在线 NODE_STATUS_OFFLINE NodeStatus = "offline" // 离线 )
type QueryAgentMetricRequest ¶
type QueryAgentMetricRequest struct {
request.PageRequest
// Agent ID
AgentId string `json:"agent_id" form:"agent_id" query:"agent_id"`
}
func NewQueryAgentMetricRequest ¶
func NewQueryAgentMetricRequest(agentId string) *QueryAgentMetricRequest
type QueryNodeRequest ¶
type QueryNodeRequest struct {
request.PageRequest
NodeName string `json:"node_name" form:"node_name" query:"node_name"` // 节点名称(模糊查询)
Status NodeStatus `json:"status" form:"status" query:"status"` // 节点状态
}
QueryNodeRequest 查询节点请求
func NewQueryNodeRequest ¶
func NewQueryNodeRequest() *QueryNodeRequest
NewQueryNodeRequest 创建查询节点请求
type RegisterNodeRequest ¶
type RegisterNodeRequest struct {
NodeName string `json:"node_name"` // 节点名称,默认使用 hostname
NodeIP string `json:"node_ip"` // 节点IP,从 NODE_IP 环境变量或自动获取
NodePort int `json:"node_port"` // 节点端口
Version string `json:"version"` // 节点版本
BuildTime string `json:"build_time"` // 构建时间
Labels map[string]string `json:"labels"` // 节点标签
}
RegisterNodeRequest 注册节点请求
type Service ¶
type Service interface {
// 节点查询
DescribeNode(ctx context.Context, nodeName string) (*Node, error)
QueryNodes(ctx context.Context, in *QueryNodeRequest) (*types.Set[*Node], error)
// SaveAgentMetric 保存 Agent 指标
SaveAgentMetric(ctx context.Context, in *NodeMetric) error
// QueryAgentMetric 查询 Agent 指标列表
QueryAgentMetric(ctx context.Context, in *QueryAgentMetricRequest) (*types.Set[*NodeMetric], error)
// DescribeLatestMetric 查询 Agent 最新指标
DescribeLatestMetric(ctx context.Context, agentId string) (*NodeMetric, error)
// 清理旧数据
CleanMetric(ctx context.Context, in *CleanMetricRequest) (*CleanMetricResponse, error)
}
func GetService ¶
func GetService() Service
Click to show internal directories.
Click to hide internal directories.