Update string parsing of allocatable cpu cores in kube_inventory (#8512)

This commit is contained in:
Joe Wang 2020-12-10 11:38:01 -08:00 committed by GitHub
parent d79a2464d3
commit 99287d89e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -191,9 +191,11 @@ subjects:
- node_name
- fields:
- capacity_cpu_cores
- capacity_millicpu_cores
- capacity_memory_bytes
- capacity_pods
- allocatable_cpu_cores
- allocatable_millicpu_cores
- allocatable_memory_bytes
- allocatable_pods

View File

@ -31,7 +31,8 @@ func (ki *KubernetesInventory) gatherNode(n v1.Node, acc telegraf.Accumulator) e
for resourceName, val := range n.Status.Capacity {
switch resourceName {
case "cpu":
fields["capacity_cpu_cores"] = atoi(val.GetString_())
fields["capacity_cpu_cores"] = convertQuantity(val.GetString_(), 1)
fields["capacity_millicpu_cores"] = convertQuantity(val.GetString_(), 1000)
case "memory":
fields["capacity_memory_bytes"] = convertQuantity(val.GetString_(), 1)
case "pods":
@ -42,7 +43,8 @@ func (ki *KubernetesInventory) gatherNode(n v1.Node, acc telegraf.Accumulator) e
for resourceName, val := range n.Status.Allocatable {
switch resourceName {
case "cpu":
fields["allocatable_cpu_cores"] = atoi(val.GetString_())
fields["allocatable_cpu_cores"] = convertQuantity(val.GetString_(), 1)
fields["allocatable_millicpu_cores"] = convertQuantity(val.GetString_(), 1000)
case "memory":
fields["allocatable_memory_bytes"] = convertQuantity(val.GetString_(), 1)
case "pods":

View File

@ -56,7 +56,7 @@ func TestNode(t *testing.T) {
"pods": {String_: toStrPtr("110")},
},
Allocatable: map[string]*resource.Quantity{
"cpu": {String_: toStrPtr("16")},
"cpu": {String_: toStrPtr("1000m")},
"ephemeral_storage_bytes": {String_: toStrPtr("44582761194")},
"hugepages_1Gi_bytes": {String_: toStrPtr("0")},
"hugepages_2Mi_bytes": {String_: toStrPtr("0")},
@ -103,12 +103,14 @@ func TestNode(t *testing.T) {
{
Measurement: nodeMeasurement,
Fields: map[string]interface{}{
"capacity_cpu_cores": int64(16),
"capacity_memory_bytes": int64(1.28837533696e+11),
"capacity_pods": int64(110),
"allocatable_cpu_cores": int64(16),
"allocatable_memory_bytes": int64(1.28732676096e+11),
"allocatable_pods": int64(110),
"capacity_cpu_cores": int64(16),
"capacity_millicpu_cores": int64(16000),
"capacity_memory_bytes": int64(1.28837533696e+11),
"capacity_pods": int64(110),
"allocatable_cpu_cores": int64(1),
"allocatable_millicpu_cores": int64(1000),
"allocatable_memory_bytes": int64(1.28732676096e+11),
"allocatable_pods": int64(110),
},
Tags: map[string]string{
"node_name": "node1",