From b82db8e0b15c2f88787618eba7268db95d3d24ea Mon Sep 17 00:00:00 2001 From: Ybehrooz Date: Sun, 31 Aug 2025 19:35:41 +0330 Subject: [PATCH] fix stats --- handler/handler.go | 35 +++++++++++++++++++++++++++++++++++ main.go | 1 + models/workloads.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/handler/handler.go b/handler/handler.go index 596dcd8..c182832 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -1070,3 +1070,38 @@ func Worker_nodes_plan(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(workerNodesPlan) } + +func ClusterStats(w http.ResponseWriter, r *http.Request) { + + data := models.ClusterStats{ + ResourceUsage: models.ResourceUsage{ + CPU: models.Usage{Used: 65, Total: 100, Unit: "cores"}, + Memory: models.Usage{Used: 8.2, Total: 16, Unit: "GB"}, + Storage: models.Usage{Used: 45, Total: 100, Unit: "GB"}, + Network: models.Usage{Used: 2.1, Total: 10, Unit: "Gbps"}, + }, + Performance: models.Performance{ + PodStartupTime: "2.3s", + APILatency: "45ms", + EtcdLatency: "12ms", + SchedulerLatency: "8ms", + }, + Health: models.Health{ + NodesHealthy: 3, + NodesTotal: 3, + PodsRunning: 10, + PodsTotal: 12, + Alerts: 2, + Warnings: 1, + }, + Uptime: models.Uptime{ + ClusterUptime: "15d 8h 32m", + LastMaintenance: "3d ago", + NextMaintenance: "11d from now", + }, + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + +} diff --git a/main.go b/main.go index 40a4731..9187905 100644 --- a/main.go +++ b/main.go @@ -128,6 +128,7 @@ func main() { router.HandleFunc("/createcluster", handler.CreateClusterHandler) router.HandleFunc("/deletecluster", handler.Deletecluster) router.HandleFunc("/clusters", handler.ListUserClusters) + router.HandleFunc("/cluster/stats", handler.ClusterStats) router.HandleFunc("/connect", handler.Connect) // router.HandleFunc("/cluster_nodes", handler.Cluster_nodes) router.HandleFunc("/cluster_namespaces", handler.Cluster_namespaces) diff --git a/models/workloads.go b/models/workloads.go index 5db9ee3..3c6b418 100644 --- a/models/workloads.go +++ b/models/workloads.go @@ -16,7 +16,7 @@ type Cluster struct { Name string `json:"name"` Namespace string `json:"namespace"` ControlPlane string `json:"controlPlane"` - PlatformVersion string `json:"platformversion` + PlatformVersion string `json:"platformversion"` Cpu string `json:"cpu"` Memory string `json:"memory"` CreatedAt string `json:"createdAt"` @@ -109,3 +109,45 @@ type WorkerNodesPlans struct { Memory string `json:memory` Storage string `;sjon:storage` } + +type ClusterStats struct { + ResourceUsage ResourceUsage `json:"resourceUsage"` + Performance Performance `json:"performance"` + Health Health `json:"health"` + Uptime Uptime `json:"uptime"` +} + +type ResourceUsage struct { + CPU Usage `json:"cpu"` + Memory Usage `json:"memory"` + Storage Usage `json:"storage"` + Network Usage `json:"network"` +} + +type Usage struct { + Used float64 `json:"used"` + Total float64 `json:"total"` + Unit string `json:"unit"` +} + +type Performance struct { + PodStartupTime string `json:"podStartupTime"` + APILatency string `json:"apiLatency"` + EtcdLatency string `json:"etcdLatency"` + SchedulerLatency string `json:"schedulerLatency"` +} + +type Health struct { + NodesHealthy int `json:"nodesHealthy"` + NodesTotal int `json:"nodesTotal"` + PodsRunning int `json:"podsRunning"` + PodsTotal int `json:"podsTotal"` + Alerts int `json:"alerts"` + Warnings int `json:"warnings"` +} + +type Uptime struct { + ClusterUptime string `json:"clusterUptime"` + LastMaintenance string `json:"lastMaintenance"` + NextMaintenance string `json:"nextMaintenance"` +}