2019-02-04 20:28:43 +00:00
|
|
|
package kube_inventory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-10-23 22:35:37 +00:00
|
|
|
"github.com/ericchiang/k8s/apis/apps/v1"
|
2019-02-04 20:28:43 +00:00
|
|
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 22:35:37 +00:00
|
|
|
func (ki *KubernetesInventory) gatherStatefulSet(s v1.StatefulSet, acc telegraf.Accumulator) error {
|
2019-02-04 20:28:43 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
acc.AddFields(statefulSetMeasurement, fields, tags)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|