forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
38 lines (33 loc) · 946 Bytes
/
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
package kube_inventory
import (
"context"
"github.com/influxdata/telegraf"
v1 "k8s.io/api/apps/v1"
)
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 {
ki.gatherDeployment(d, acc)
}
}
func (ki *KubernetesInventory) gatherDeployment(d v1.Deployment, acc telegraf.Accumulator) {
fields := map[string]interface{}{
"replicas_available": d.Status.AvailableReplicas,
"replicas_unavailable": d.Status.UnavailableReplicas,
"created": d.GetCreationTimestamp().UnixNano(),
}
tags := map[string]string{
"deployment_name": d.Name,
"namespace": d.Namespace,
}
for key, val := range d.Spec.Selector.MatchLabels {
if ki.selectorFilter.Match(key) {
tags["selector_"+key] = val
}
}
acc.AddFields(deploymentMeasurement, fields, tags)
}