Skip to content

Commit

Permalink
track node total requested memory/cpu (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoulgrave authored Dec 24, 2020
1 parent d89d99f commit e5e9056
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ For in cluster development process [Minikube](https://kubernetes.io/docs/setup/l
### Configuration

* Copy the daemonset file `deploy/newrelic-infra.yaml` to `deploy/local.yaml`.
* Edit the file and set the following value as container image: `newrelic/infrastructure-k8s-dev`.
* Edit the file and set the following value as container image: `quay.io/newrelic/infrastructure-k8s-dev`.

```yaml
containers:
- name: newrelic-infra
image: newrelic/infrastructure-k8s-dev
image: quay.io/newrelic/infrastructure-k8s-dev
resources:
```
Expand Down
4 changes: 2 additions & 2 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta7
apiVersion: skaffold/v2beta10
kind: Config
build:
tagPolicy:
Expand Down Expand Up @@ -49,4 +49,4 @@ profiles:
deploy:
kubectl:
manifests:
- deploy/local-openshift.yaml
- deploy/local-openshift.yaml
25 changes: 22 additions & 3 deletions src/kubelet/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,31 @@ func (r *kubelet) Group(definition.SpecGroups) (definition.RawGroups, *data.Erro
Errors: []error{fmt.Errorf("error querying ApiServer: %v", err)},
}
}

var requestedCPUMillis, requestedMemoryBytes int64

if _, ok := rawGroups["container"]; ok {
for _, container := range rawGroups["container"] {
if containerMemoryRequestedBytes, ok := container["memoryRequestedBytes"]; ok {
// if this map key exist, it's Quantity.MilliValue() (int64)
requestedMemoryBytes += containerMemoryRequestedBytes.(int64)
}

if containerCPURequestedCores, ok := container["cpuRequestedCores"]; ok {
// if this map key exist, it's Quantity.MilliValue() (int64)
requestedCPUMillis += containerCPURequestedCores.(int64)
}
}
}

g := definition.RawGroups{
"node": {
response.Node.NodeName: definition.RawMetrics{
"labels": nodeInfo.Labels,
"allocatable": nodeInfo.Allocatable,
"capacity": nodeInfo.Capacity,
"labels": nodeInfo.Labels,
"allocatable": nodeInfo.Allocatable,
"capacity": nodeInfo.Capacity,
"memoryRequestedBytes": requestedMemoryBytes,
"cpuRequestedCores": requestedCPUMillis,
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions src/kubelet/metric/testdata/kubelet_group_expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ var ExpectedGroupData = definition.RawGroups{
"memoryAvailableBytes": uint64(791736320),
"memoryMajorPageFaults": uint64(0),
"memoryPageFaults": uint64(113947),
"memoryRequestedBytes": int64(243269632),
"memoryRssBytes": uint64(660684800),
"memoryUsageBytes": uint64(1843650560),
"memoryWorkingSetBytes": uint64(1305468928),
Expand All @@ -273,6 +274,7 @@ var ExpectedGroupData = definition.RawGroups{
"kubernetes.io/os": "linux",
"node-role.kubernetes.io/master": "",
},
"cpuRequestedCores": int64(501),
"allocatable": v1.ResourceList{
v1.ResourceCPU: *resource.NewQuantity(2, resource.DecimalSI),
v1.ResourcePods: *resource.NewQuantity(110, resource.DecimalSI),
Expand Down Expand Up @@ -641,6 +643,7 @@ var ExpectedGroupDataWithoutStaticPodsStatus = definition.RawGroups{
"minikube": {
"nodeName": "minikube",
"errors": uint64(0),
"memoryRequestedBytes": int64(243269632),
"fsAvailableBytes": uint64(14924988416),
"fsCapacityBytes": uint64(17293533184),
"fsInodes": uint64(9732096),
Expand All @@ -663,6 +666,7 @@ var ExpectedGroupDataWithoutStaticPodsStatus = definition.RawGroups{
"txBytes": uint64(120789968),
"usageCoreNanoSeconds": uint64(22332102208229),
"usageNanoCores": uint64(228759290),
"cpuRequestedCores": int64(501),
"labels": map[string]string{
"kubernetes.io/arch": "amd64",
"kubernetes.io/hostname": "minikube",
Expand Down
2 changes: 2 additions & 0 deletions src/metric/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ var KubeletSpecs = definition.SpecGroups{
{Name: "label.*", ValueFunc: definition.Transform(definition.FromRaw("labels"), kubeletMetric.OneMetricPerLabel), Type: sdkMetric.ATTRIBUTE},
{Name: "allocatable.*", ValueFunc: definition.Transform(definition.FromRaw("allocatable"), kubeletMetric.OneAttributePerAllocatable), Type: sdkMetric.GAUGE},
{Name: "capacity.*", ValueFunc: definition.Transform(definition.FromRaw("capacity"), kubeletMetric.OneAttributePerCapacity), Type: sdkMetric.GAUGE},
{Name: "memoryRequestedBytes", ValueFunc: definition.FromRaw("memoryRequestedBytes"), Type: sdkMetric.GAUGE},
{Name: "cpuRequestedCores", ValueFunc: definition.FromRaw("cpuRequestedCores"), Type: sdkMetric.GAUGE},
},
},
"volume": {
Expand Down

0 comments on commit e5e9056

Please sign in to comment.