Skip to content

Commit

Permalink
fix get monitoring result (#4242)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 authored Nov 9, 2023
1 parent bd68a73 commit 6d71ab2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions controllers/resources/controllers/monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,16 @@ func (r *MonitorReconciler) getResourceUsage(namespace string) ([]*resources.Mon
return nil, err
}
for _, pod := range podList.Items {
//TODO if pod is job && 结束时候到现在时间小于1分钟 统计资源
if pod.Status.Phase == corev1.PodSucceeded || pod.Spec.NodeName == "" {
if pod.Spec.NodeName == "" || (pod.Status.Phase == corev1.PodSucceeded && time.Since(pod.Status.StartTime.Time) > 1*time.Minute) {
continue
}
podResNamed := resources.NewResourceNamed(&pod)
resourceMap[podResNamed.String()] = podResNamed
if podsRes[podResNamed.String()] == nil {
podsRes[podResNamed.String()] = initResources()
}
// skip pods that do not start for more than 1 minute
skip := pod.Status.Phase != corev1.PodRunning && (pod.Status.StartTime == nil || time.Since(pod.Status.StartTime.Time) > 1*time.Minute)
for _, container := range pod.Spec.Containers {
// gpu only use limit and not ignore pod pending status
if gpuRequest, ok := container.Resources.Limits[gpu.NvidiaGpuKey]; ok {
Expand All @@ -260,7 +261,7 @@ func (r *MonitorReconciler) getResourceUsage(namespace string) ([]*resources.Mon
r.Logger.Error(err, "get gpu resource usage failed", "pod", pod.Name)
}
}
if pod.Status.Phase != corev1.PodRunning {
if skip {
continue
}
if cpuRequest, ok := container.Resources.Limits[corev1.ResourceCPU]; ok {
Expand All @@ -283,7 +284,7 @@ func (r *MonitorReconciler) getResourceUsage(namespace string) ([]*resources.Mon
return nil, fmt.Errorf("failed to list pvc: %v", err)
}
for _, pvc := range pvcList.Items {
if pvc.Status.Phase != corev1.ClaimBound {
if pvc.Status.Phase != corev1.ClaimBound || pvc.Name == resources.KubeBlocksBackUpName {
continue
}
pvcRes := resources.NewResourceNamed(&pvc)
Expand Down

0 comments on commit 6d71ab2

Please sign in to comment.