2019-02-04 20:28:43 +00:00
|
|
|
package kube_inventory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-10-23 22:35:37 +00:00
|
|
|
v1 "github.com/ericchiang/k8s/apis/apps/v1"
|
2019-02-04 20:28:43 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func collectDeployments(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
|
|
|
|
list, err := ki.client.getDeployments(ctx)
|
|
|
|
if err != nil {
|
|
|
|
acc.AddError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, d := range list.Items {
|
|
|
|
if err = ki.gatherDeployment(*d, acc); err != nil {
|
|
|
|
acc.AddError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 22:35:37 +00:00
|
|
|
func (ki *KubernetesInventory) gatherDeployment(d v1.Deployment, acc telegraf.Accumulator) error {
|
2019-02-04 20:28:43 +00:00
|
|
|
fields := map[string]interface{}{
|
|
|
|
"replicas_available": d.Status.GetAvailableReplicas(),
|
|
|
|
"replicas_unavailable": d.Status.GetUnavailableReplicas(),
|
|
|
|
"created": time.Unix(d.Metadata.CreationTimestamp.GetSeconds(), int64(d.Metadata.CreationTimestamp.GetNanos())).UnixNano(),
|
|
|
|
}
|
|
|
|
tags := map[string]string{
|
|
|
|
"deployment_name": d.Metadata.GetName(),
|
|
|
|
"namespace": d.Metadata.GetNamespace(),
|
|
|
|
}
|
|
|
|
|
|
|
|
acc.AddFields(deploymentMeasurement, fields, tags)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|