Files
ocdp-go/backend/internal/adapter/input/http/dto/monitoring_dto.go
Ivan087 7f238a3168 refactor: full-stack restructure with multi-tenancy, workspace management, and K8s diagnostics
- Add Workspace domain (entity, repository, service, handler, DTO)
- Add multi-tenant K8s client with tenant binding and quota management
- Add K8s diagnostics client (instance diagnostics)
- Add authorization middleware (authz package)
- Restructure frontend to feature-based architecture (features/)
- Add User Management page in configuration
- Add AccessDenied page and route guards
- Refactor shared components (form inputs, layout, UI)
- Update Tailwind config for new design system
- Add comprehensive documentation (docs/, tasks/, plans)
- Improve cluster service with better kubeconfig handling
- Add tests for crypto, config, helm client, tenant binding
2026-05-12 16:15:14 +08:00

143 lines
5.3 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,
}
}