Skip to content

Commit

Permalink
feat(monitor): add total CPU and memory to the overview interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wangao1236 authored and tke-robot committed Aug 30, 2020
1 parent 402ff1f commit 0686946
Show file tree
Hide file tree
Showing 8 changed files with 505 additions and 236 deletions.
7 changes: 7 additions & 0 deletions api/monitor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,17 @@ type ClusterOverviewResult struct {
NodeAbnormal int32
WorkloadCount int32
WorkloadAbnormal int32
CPUCapacity float64
CPUAllocatable float64
MemCapacity int64
MemAllocatable int64
PodCount int32
Clusters []*ClusterStatistic
}

type ClusterStatistic struct {
ClusterID string
TenantID string
ClusterPhase string
NodeCount int32
NodeAbnormal int32
Expand All @@ -242,6 +248,7 @@ type ClusterStatistic struct {
MemRequestRate string
MemAllocatableRate string
MemUsage string
PodCount int32
SchedulerHealthy bool
ControllerManagerHealthy bool
EtcdHealthy bool
Expand Down
541 changes: 359 additions & 182 deletions api/monitor/v1/generated.pb.go

Large diffs are not rendered by default.

66 changes: 40 additions & 26 deletions api/monitor/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 33 additions & 26 deletions api/monitor/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,36 +214,43 @@ type ClusterOverviewResult struct {
NodeAbnormal int32 `json:"nodeAbnormal" protobuf:"bytes,6,opt,name=nodeAbnormal"`
WorkloadCount int32 `json:"workloadCount" protobuf:"bytes,7,opt,name=workloadCount"`
WorkloadAbnormal int32 `json:"workloadAbnormal" protobuf:"bytes,8,opt,name=workloadAbnormal"`
Clusters []*ClusterStatistic `json:"clusters" protobuf:"bytes,9,opt,name=clusters"`
CPUCapacity float64 `json:"cpuCapacity" protobuf:"bytes,9,opt,name=cpuCapacity"`
CPUAllocatable float64 `json:"cpuAllocatable" protobuf:"bytes,10,opt,name=cpuAllocatable"`
MemCapacity int64 `json:"memCapacity" protobuf:"bytes,11,opt,name=memCapacity"`
MemAllocatable int64 `json:"memAllocatable" protobuf:"bytes,12,opt,name=memAllocatable"`
PodCount int32 `json:"podCount" protobuf:"bytes,13,opt,name=podCount"`
Clusters []*ClusterStatistic `json:"clusters" protobuf:"bytes,14,opt,name=clusters"`
}

type ClusterStatistic struct {
ClusterID string `json:"clusterID" protobuf:"bytes,1,opt,name=clusterID"`
ClusterPhase string `json:"clusterPhase" protobuf:"bytes,2,opt,name=clusterPhase"`
NodeCount int32 `json:"nodeCount" protobuf:"bytes,3,opt,name=nodeCount"`
NodeAbnormal int32 `json:"nodeAbnormal" protobuf:"bytes,4,opt,name=nodeAbnormal"`
WorkloadCount int32 `json:"workloadCount" protobuf:"bytes,5,opt,name=workloadCount"`
WorkloadAbnormal int32 `json:"workloadAbnormal" protobuf:"bytes,6,opt,name=workloadAbnormal"`
HasMetricServer bool `json:"hasMetricServer" protobuf:"bytes,7,opt,name=hasMetricServer"`
CPUUsed float64 `json:"cpuUsed" protobuf:"bytes,8,opt,name=cpuUsed"`
CPURequest float64 `json:"cpuRequest" protobuf:"bytes,9,opt,name=cpuRequest"`
CPULimit float64 `json:"cpuLimit" protobuf:"bytes,10,opt,name=cpuLimit"`
CPUCapacity float64 `json:"cpuCapacity" protobuf:"bytes,11,opt,name=cpuCapacity"`
CPUAllocatable float64 `json:"cpuAllocatable" protobuf:"bytes,12,opt,name=cpuAllocatable"`
CPURequestRate string `json:"cpuRequestRate" protobuf:"bytes,13,opt,name=cpuRequestRate"`
CPUAllocatableRate string `json:"cpuAllocatableRate" protobuf:"bytes,14,opt,name=cpuAllocatableRate"`
CPUUsage string `json:"cpuUsage" protobuf:"bytes,15,opt,name=cpuUsage"`
MemUsed int64 `json:"memUsed" protobuf:"bytes,16,opt,name=memUsed"`
MemRequest int64 `json:"memRequest" protobuf:"bytes,17,opt,name=memRequest"`
MemLimit int64 `json:"memLimit" protobuf:"bytes,18,opt,name=memLimit"`
MemCapacity int64 `json:"memCapacity" protobuf:"bytes,19,opt,name=memCapacity"`
MemAllocatable int64 `json:"memAllocatable" protobuf:"bytes,20,opt,name=memAllocatable"`
MemRequestRate string `json:"memRequestRate" protobuf:"bytes,21,opt,name=memRequestRate"`
MemAllocatableRate string `json:"memAllocatableRate" protobuf:"bytes,22,opt,name=memAllocatableRate"`
MemUsage string `json:"memUsage" protobuf:"bytes,23,opt,name=memUsage"`
SchedulerHealthy bool `json:"schedulerHealthy" protobuf:"bytes,24,opt,name=schedulerHealthy"`
ControllerManagerHealthy bool `json:"controllerManagerHealthy" protobuf:"bytes,25,opt,name=controllerManagerHealthy"`
EtcdHealthy bool `json:"etcdHealthy" protobuf:"bytes,26,opt,name=etcdHealthy"`
TenantID string `json:"tenantID" protobuf:"bytes,2,opt,name=tenantID"`
ClusterPhase string `json:"clusterPhase" protobuf:"bytes,3,opt,name=clusterPhase"`
NodeCount int32 `json:"nodeCount" protobuf:"bytes,4,opt,name=nodeCount"`
NodeAbnormal int32 `json:"nodeAbnormal" protobuf:"bytes,5,opt,name=nodeAbnormal"`
WorkloadCount int32 `json:"workloadCount" protobuf:"bytes,6,opt,name=workloadCount"`
WorkloadAbnormal int32 `json:"workloadAbnormal" protobuf:"bytes,7,opt,name=workloadAbnormal"`
HasMetricServer bool `json:"hasMetricServer" protobuf:"bytes,8,opt,name=hasMetricServer"`
CPUUsed float64 `json:"cpuUsed" protobuf:"bytes,9,opt,name=cpuUsed"`
CPURequest float64 `json:"cpuRequest" protobuf:"bytes,10,opt,name=cpuRequest"`
CPULimit float64 `json:"cpuLimit" protobuf:"bytes,11,opt,name=cpuLimit"`
CPUCapacity float64 `json:"cpuCapacity" protobuf:"bytes,12,opt,name=cpuCapacity"`
CPUAllocatable float64 `json:"cpuAllocatable" protobuf:"bytes,13,opt,name=cpuAllocatable"`
CPURequestRate string `json:"cpuRequestRate" protobuf:"bytes,14,opt,name=cpuRequestRate"`
CPUAllocatableRate string `json:"cpuAllocatableRate" protobuf:"bytes,15,opt,name=cpuAllocatableRate"`
CPUUsage string `json:"cpuUsage" protobuf:"bytes,16,opt,name=cpuUsage"`
MemUsed int64 `json:"memUsed" protobuf:"bytes,17,opt,name=memUsed"`
MemRequest int64 `json:"memRequest" protobuf:"bytes,18,opt,name=memRequest"`
MemLimit int64 `json:"memLimit" protobuf:"bytes,19,opt,name=memLimit"`
MemCapacity int64 `json:"memCapacity" protobuf:"bytes,20,opt,name=memCapacity"`
MemAllocatable int64 `json:"memAllocatable" protobuf:"bytes,21,opt,name=memAllocatable"`
MemRequestRate string `json:"memRequestRate" protobuf:"bytes,22,opt,name=memRequestRate"`
MemAllocatableRate string `json:"memAllocatableRate" protobuf:"bytes,23,opt,name=memAllocatableRate"`
MemUsage string `json:"memUsage" protobuf:"bytes,24,opt,name=memUsage"`
PodCount int32 `json:"podCount" protobuf:"bytes,25,opt,name=podCount"`
SchedulerHealthy bool `json:"schedulerHealthy" protobuf:"bytes,26,opt,name=schedulerHealthy"`
ControllerManagerHealthy bool `json:"controllerManagerHealthy" protobuf:"bytes,27,opt,name=controllerManagerHealthy"`
EtcdHealthy bool `json:"etcdHealthy" protobuf:"bytes,28,opt,name=etcdHealthy"`
}

// +genclient
Expand Down
14 changes: 14 additions & 0 deletions api/monitor/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/monitor/util/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (c *cacher) getClusters() {
MemRequestRate: transPercent(resourceCounter.MemRequestRate),
MemAllocatableRate: transPercent(resourceCounter.MemAllocatableRate),
MemUsage: transPercent(resourceCounter.MemUsage),
PodCount: int32(resourceCounter.PodCount),
SchedulerHealthy: health.Scheduler,
ControllerManagerHealthy: health.ControllerManager,
EtcdHealthy: health.Etcd,
Expand Down Expand Up @@ -264,6 +265,11 @@ func (c *cacher) GetClusterOverviewResult(clusterIDs []string) *monitor.ClusterO
result.NodeAbnormal += clusterStatistic.NodeAbnormal
result.WorkloadCount += clusterStatistic.WorkloadCount
result.WorkloadAbnormal += clusterStatistic.WorkloadAbnormal
result.CPUCapacity += clusterStatistic.CPUCapacity
result.CPUAllocatable += clusterStatistic.CPUAllocatable
result.MemCapacity += clusterStatistic.MemCapacity
result.MemAllocatable += clusterStatistic.MemAllocatable
result.PodCount += clusterStatistic.PodCount
clusterStatistics = append(clusterStatistics, clusterStatistic)
}
}
Expand Down Expand Up @@ -407,6 +413,7 @@ func (c *cacher) getNodes(clusterID string, clientSet *kubernetes.Clientset, cou

func (c *cacher) getPods(clusterID string, clientSet *kubernetes.Clientset, counter *util.ResourceCounter) {
if pods, err := clientSet.CoreV1().Pods(AllNamespaces).List(context.Background(), metav1.ListOptions{}); err == nil {
counter.PodCount = len(pods.Items)
for _, pod := range pods.Items {
for _, ctn := range pod.Spec.Containers {
counter.CPURequest += float64(ctn.Resources.Requests.Cpu().MilliValue()) / float64(1000)
Expand Down
1 change: 1 addition & 0 deletions pkg/monitor/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type ResourceCounter struct {
MemRequestRate float64
MemAllocatableRate float64
MemUsage float64
PodCount int
}

type ComponentHealth struct {
Expand Down

0 comments on commit 0686946

Please sign in to comment.