forked from SumoLogic/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statefulset.go
51 lines (44 loc) · 1.38 KB
/
statefulset.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
package kube_inventory
import (
"context"
"time"
"github.com/ericchiang/k8s/apis/apps/v1"
"github.com/influxdata/telegraf"
)
func collectStatefulSets(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getStatefulSets(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, s := range list.Items {
if err = ki.gatherStatefulSet(*s, acc); err != nil {
acc.AddError(err)
return
}
}
}
func (ki *KubernetesInventory) gatherStatefulSet(s v1.StatefulSet, acc telegraf.Accumulator) error {
status := s.Status
fields := map[string]interface{}{
"created": time.Unix(s.Metadata.CreationTimestamp.GetSeconds(), int64(s.Metadata.CreationTimestamp.GetNanos())).UnixNano(),
"generation": *s.Metadata.Generation,
"replicas": *status.Replicas,
"replicas_current": *status.CurrentReplicas,
"replicas_ready": *status.ReadyReplicas,
"replicas_updated": *status.UpdatedReplicas,
"spec_replicas": *s.Spec.Replicas,
"observed_generation": *s.Status.ObservedGeneration,
}
tags := map[string]string{
"statefulset_name": *s.Metadata.Name,
"namespace": *s.Metadata.Namespace,
}
for key, val := range s.GetSpec().GetSelector().GetMatchLabels() {
if ki.selectorFilter.Match(key) {
tags["selector_"+key] = val
}
}
acc.AddFields(statefulSetMeasurement, fields, tags)
return nil
}