144 lines
5.1 KiB
Go
144 lines
5.1 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ocdp/cluster-service/internal/domain/entity"
|
|
)
|
|
|
|
// ClusterMetricsResponse 集群监控响应
|
|
type ClusterMetricsResponse struct {
|
|
ClusterID string `json:"clusterId"`
|
|
ClusterName string `json:"clusterName"`
|
|
Status string `json:"status"`
|
|
Uptime string `json:"uptime"`
|
|
NodeCount int `json:"nodeCount"`
|
|
PodCount int `json:"podCount"`
|
|
LastCheck time.Time `json:"lastCheck"`
|
|
TotalCPU string `json:"totalCpu"`
|
|
TotalMemory string `json:"totalMemory"`
|
|
TotalGPU int `json:"totalGpu"`
|
|
UsedCPU string `json:"usedCpu"`
|
|
UsedMemory string `json:"usedMemory"`
|
|
UsedGPU int `json:"usedGpu"`
|
|
CPUUsage float64 `json:"cpuUsage"`
|
|
MemoryUsage float64 `json:"memoryUsage"`
|
|
GPUUsage float64 `json:"gpuUsage"`
|
|
MaxNodeCPU string `json:"maxNodeCpu"`
|
|
MaxNodeMemory string `json:"maxNodeMemory"`
|
|
MaxNodeGPU int `json:"maxNodeGpu"`
|
|
MaxNodeCPUUsage float64 `json:"maxNodeCpuUsage"`
|
|
MaxNodeMemUsage float64 `json:"maxNodeMemUsage"`
|
|
MaxNodeGPUUsage float64 `json:"maxNodeGpuUsage"`
|
|
Nodes []NodeMetricsResponse `json:"nodes,omitempty"`
|
|
}
|
|
|
|
// NodeMetricsResponse 节点监控响应
|
|
type NodeMetricsResponse struct {
|
|
NodeName string `json:"nodeName"`
|
|
Status string `json:"status"`
|
|
Role string `json:"role"`
|
|
Age string `json:"age"`
|
|
PodCount int `json:"podCount"`
|
|
CPUCapacity string `json:"cpuCapacity"`
|
|
CPUAllocatable string `json:"cpuAllocatable"`
|
|
CPUUsage string `json:"cpuUsage"`
|
|
CPUPercent float64 `json:"cpuPercent"`
|
|
MemoryCapacity string `json:"memoryCapacity"`
|
|
MemoryAllocatable string `json:"memoryAllocatable"`
|
|
MemoryUsage string `json:"memoryUsage"`
|
|
MemoryPercent float64 `json:"memoryPercent"`
|
|
GPUCapacity int `json:"gpuCapacity"`
|
|
GPUUsage int `json:"gpuUsage"`
|
|
GPUPercent float64 `json:"gpuPercent"`
|
|
GPUType string `json:"gpuType,omitempty"`
|
|
OSImage string `json:"osImage,omitempty"`
|
|
KernelVersion string `json:"kernelVersion,omitempty"`
|
|
ContainerRuntime string `json:"containerRuntime,omitempty"`
|
|
KubeletVersion string `json:"kubeletVersion,omitempty"`
|
|
}
|
|
|
|
// MonitoringSummaryResponse 监控汇总响应
|
|
type MonitoringSummaryResponse struct {
|
|
TotalClusters int `json:"totalClusters"`
|
|
HealthyClusters int `json:"healthyClusters"`
|
|
WarningClusters int `json:"warningClusters"`
|
|
ErrorClusters int `json:"errorClusters"`
|
|
TotalNodes int `json:"totalNodes"`
|
|
TotalPods int `json:"totalPods"`
|
|
LastUpdate time.Time `json:"lastUpdate"`
|
|
}
|
|
|
|
// ToClusterMetricsResponse 转换为响应
|
|
func ToClusterMetricsResponse(m *entity.ClusterMetrics) *ClusterMetricsResponse {
|
|
resp := &ClusterMetricsResponse{
|
|
ClusterID: m.ClusterID,
|
|
ClusterName: m.ClusterName,
|
|
Status: m.Status,
|
|
Uptime: m.Uptime,
|
|
NodeCount: m.NodeCount,
|
|
PodCount: m.PodCount,
|
|
LastCheck: m.LastCheck,
|
|
TotalCPU: m.TotalCPU,
|
|
TotalMemory: m.TotalMemory,
|
|
TotalGPU: m.TotalGPU,
|
|
UsedCPU: m.UsedCPU,
|
|
UsedMemory: m.UsedMemory,
|
|
UsedGPU: m.UsedGPU,
|
|
CPUUsage: m.CPUUsage,
|
|
MemoryUsage: m.MemoryUsage,
|
|
GPUUsage: m.GPUUsage,
|
|
MaxNodeCPU: m.MaxNodeCPU,
|
|
MaxNodeMemory: m.MaxNodeMemory,
|
|
MaxNodeGPU: m.MaxNodeGPU,
|
|
MaxNodeCPUUsage: m.MaxNodeCPUUsage,
|
|
MaxNodeMemUsage: m.MaxNodeMemUsage,
|
|
MaxNodeGPUUsage: m.MaxNodeGPUUsage,
|
|
}
|
|
|
|
if len(m.Nodes) > 0 {
|
|
resp.Nodes = make([]NodeMetricsResponse, len(m.Nodes))
|
|
for i, node := range m.Nodes {
|
|
resp.Nodes[i] = NodeMetricsResponse{
|
|
NodeName: node.NodeName,
|
|
Status: node.Status,
|
|
Role: node.Role,
|
|
Age: node.Age,
|
|
PodCount: node.PodCount,
|
|
CPUCapacity: node.CPUCapacity,
|
|
CPUAllocatable: node.CPUAllocatable,
|
|
CPUUsage: node.CPUUsage,
|
|
CPUPercent: node.CPUPercent,
|
|
MemoryCapacity: node.MemoryCapacity,
|
|
MemoryAllocatable: node.MemoryAllocatable,
|
|
MemoryUsage: node.MemoryUsage,
|
|
MemoryPercent: node.MemoryPercent,
|
|
GPUCapacity: node.GPUCapacity,
|
|
GPUUsage: node.GPUUsage,
|
|
GPUPercent: node.GPUPercent,
|
|
GPUType: node.GPUType,
|
|
OSImage: node.OSImage,
|
|
KernelVersion: node.KernelVersion,
|
|
ContainerRuntime: node.ContainerRuntime,
|
|
KubeletVersion: node.KubeletVersion,
|
|
}
|
|
}
|
|
}
|
|
|
|
return resp
|
|
}
|
|
|
|
// ToMonitoringSummaryResponse 转换为汇总响应
|
|
func ToMonitoringSummaryResponse(s *entity.MonitoringSummary) *MonitoringSummaryResponse {
|
|
return &MonitoringSummaryResponse{
|
|
TotalClusters: s.TotalClusters,
|
|
HealthyClusters: s.HealthyClusters,
|
|
WarningClusters: s.WarningClusters,
|
|
ErrorClusters: s.ErrorClusters,
|
|
TotalNodes: s.TotalNodes,
|
|
TotalPods: s.TotalPods,
|
|
LastUpdate: s.LastUpdate,
|
|
}
|
|
}
|
|
|