Skip to content

Commit

Permalink
Update string parsing of allocatable cpu cores in kube_inventory (inf…
Browse files Browse the repository at this point in the history
  • Loading branch information
j03wang authored Dec 10, 2020
1 parent d79a246 commit 99287d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions plugins/inputs/kube_inventory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions plugins/inputs/kube_inventory/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand Down
16 changes: 9 additions & 7 deletions plugins/inputs/kube_inventory/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 99287d8

Please sign in to comment.