package model // NodeState 节点状态信息 type NodeState struct { Uptime uint64 `xorm:"BIGINT pk" json:"uptime,omitempty"` NodeName string `xorm:"varchar(100) pk" json:"nodeName"` CPU float64 `xorm:"DECIMAL(18,4)" json:"cpu,omitempty"` MemUsed uint64 `xorm:"BIGINT" json:"memUsed,omitempty"` SwapUsed uint64 `xorm:"BIGINT" json:"swapUsed,omitempty"` DiskUsed uint64 `xorm:"BIGINT" json:"diskUsed,omitempty"` NetInTransfer uint64 `xorm:"BIGINT" json:"netInTransfer,omitempty"` NetOutTransfer uint64 `xorm:"BIGINT" json:"netOutTransfer,omitempty"` NetInSpeed uint64 `xorm:"BIGINT" json:"netInSpeed,omitempty"` NetOutSpeed uint64 `xorm:"BIGINT" json:"netOutSpeed,omitempty"` Load1 float64 `xorm:"DECIMAL(18,4)" json:"load1,omitempty"` Load5 float64 `xorm:"DECIMAL(18,4)" json:"load5,omitempty"` Load15 float64 `xorm:"DECIMAL(18,4)" json:"load15,omitempty"` TcpConnCount uint64 `xorm:"BIGINT" json:"tcpConnCount,omitempty"` UdpConnCount uint64 `xorm:"BIGINT" json:"udpConnCount,omitempty"` ProcessCount uint64 `xorm:"BIGINT" json:"processCount,omitempty"` } type NodeLastStateItem struct { NodeId int64 `json:"nodeId"` NodeGuid string `json:"nodeGuid"` NodeName string `json:"nodeName"` NodeType int `json:"nodeType"` MemTotal uint64 `json:"memTotal"` SwapTotal uint64 `json:"swapTotal"` CpuUsed float64 `json:"cpuUsed"` MemUsed uint64 `json:"memUsed"` SwapUsed uint64 `json:"swapUsed"` Load1 float64 `json:"load1"` Load5 float64 `json:"load5"` Load15 float64 `json:"load15"` ExecTask string `json:"execTask"` } func GetNodeState(nodeList []Node) []NodeLastStateItem { list := make([]NodeLastStateItem, 0) err := DB.SQL(`select c.node_id,c.node_name,c.node_guid,c.node_type,c.node_type,c.mem_total, c.swap_total,a.c_p_u cpu_used, a.mem_used,a.swap_used, a.load1, a.load5, a.load15, d.task_name exec_task from node_state a , (select node_name, max(uptime) uptime from node_state group by node_name) b, node c left join (select t2.node_id, t2.task_name from task t2, (select node_id, max(start_time) start from task group by node_id) t1 where t2.node_id = t1.node_id and t2.start_time = t1.start and t2.status = 1) d on c.node_id = d.node_id where a.node_name = b.node_name and a.uptime = b.uptime and a.node_name = c.node_guid and c.node_status > 0 `).Find(&list) if err != nil { return nil } resList := make([]NodeLastStateItem, 0) for _, v := range list { for _, val := range nodeList { if v.NodeGuid == val.NodeGuid { resList = append(resList, v) break } } } return resList }