-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add metric ext_cpu_total_distribute for local state
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
examples/ensurance/disablescheduling-when-ext-cpu-total-distribute.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: ensurance.crane.io/v1alpha1 | ||
kind: NodeQOSEnsurancePolicy | ||
metadata: | ||
name: "disablescheduling-when-ext-cpu-total-distribute" | ||
labels: | ||
app: "system" | ||
spec: | ||
nodeQualityProbe: | ||
timeoutSeconds: 10 | ||
nodeLocalGet: | ||
localCacheTTLSeconds: 60 | ||
objectiveEnsurances: | ||
- name: "ext_cpu_total_distribute" | ||
avoidanceThreshold: 2 | ||
restoreThreshold: 2 | ||
actionName: "disablescheduling" | ||
strategy: "None" | ||
metricRule: | ||
name: "ext_cpu_total_distribute" | ||
value: 110 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package noderesource | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
"k8s.io/apimachinery/pkg/labels" | ||
v1 "k8s.io/client-go/listers/core/v1" | ||
"k8s.io/klog/v2" | ||
|
||
"github.com/gocrane/crane/pkg/common" | ||
"github.com/gocrane/crane/pkg/ensurance/collector/types" | ||
"github.com/gocrane/crane/pkg/utils" | ||
) | ||
|
||
type NodeResource struct { | ||
nodeName string | ||
nodeLister v1.NodeLister | ||
podLister v1.PodLister | ||
} | ||
|
||
func NewNodeResourceCollector(nodeName string, nodeLister v1.NodeLister, podLister v1.PodLister) *NodeResource { | ||
klog.V(4).Infof("NodeResourceCollector create") | ||
return &NodeResource{ | ||
nodeName: nodeName, | ||
nodeLister: nodeLister, | ||
podLister: podLister, | ||
} | ||
} | ||
|
||
func (n *NodeResource) GetType() types.CollectType { | ||
return types.NodeResourceCollectorType | ||
} | ||
|
||
func (n *NodeResource) Collect() (map[string][]common.TimeSeries, error) { | ||
klog.V(6).Infof("NodeResourceCollector Collect") | ||
node, err := n.nodeLister.Get(n.nodeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pods, err := n.podLister.List(labels.Everything()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
allExtCpu := node.Status.Allocatable.Name(corev1.ResourceName(fmt.Sprintf(utils.ExtResourcePrefixFormat, corev1.ResourceCPU.String())), resource.DecimalSI).MilliValue() | ||
var distributeExtCpu int64 = 0 | ||
for _, pod := range pods { | ||
for _, container := range pod.Spec.Containers { | ||
if quantity, ok := container.Resources.Requests[corev1.ResourceName(fmt.Sprintf(utils.ExtResourcePrefixFormat, corev1.ResourceCPU.String()))]; ok { | ||
distributeExtCpu += quantity.MilliValue() | ||
} | ||
} | ||
} | ||
klog.V(4).Infof("allExtCpu: %d, distributeExtCpu: %d", allExtCpu, distributeExtCpu) | ||
return map[string][]common.TimeSeries{string(types.MetricNameExtCpuTotalDistribute): {{Samples: []common.Sample{{Value: (float64(distributeExtCpu) / float64(allExtCpu)) * 100, Timestamp: time.Now().Unix()}}}}}, nil | ||
} | ||
|
||
func (n *NodeResource) Stop() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters