forked from SumoLogic/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
56 lines (47 loc) · 1.28 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package kube_inventory
import (
"context"
"github.com/ericchiang/k8s/apis/core/v1"
"github.com/influxdata/telegraf"
)
func collectNodes(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getNodes(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, n := range list.Items {
if err = ki.gatherNode(*n, acc); err != nil {
acc.AddError(err)
return
}
}
}
func (ki *KubernetesInventory) gatherNode(n v1.Node, acc telegraf.Accumulator) error {
fields := map[string]interface{}{}
tags := map[string]string{
"node_name": *n.Metadata.Name,
}
for resourceName, val := range n.Status.Capacity {
switch resourceName {
case "cpu":
fields["capacity_cpu_cores"] = atoi(val.GetString_())
case "memory":
fields["capacity_memory_bytes"] = convertQuantity(val.GetString_(), 1)
case "pods":
fields["capacity_pods"] = atoi(val.GetString_())
}
}
for resourceName, val := range n.Status.Allocatable {
switch resourceName {
case "cpu":
fields["allocatable_cpu_cores"] = atoi(val.GetString_())
case "memory":
fields["allocatable_memory_bytes"] = convertQuantity(val.GetString_(), 1)
case "pods":
fields["allocatable_pods"] = atoi(val.GetString_())
}
}
acc.AddFields(nodeMeasurement, fields, tags)
return nil
}