forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
39 lines (33 loc) · 1.01 KB
/
deployment.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
package kube_inventory
import (
"context"
"time"
v1 "github.com/ericchiang/k8s/apis/apps/v1"
"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
}
}
}
func (ki *KubernetesInventory) gatherDeployment(d v1.Deployment, acc telegraf.Accumulator) error {
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
}