forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersistentvolumeclaim.go
51 lines (45 loc) · 1.16 KB
/
persistentvolumeclaim.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"
"strings"
corev1 "k8s.io/api/core/v1"
"github.com/influxdata/telegraf"
)
func collectPersistentVolumeClaims(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getPersistentVolumeClaims(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, pvc := range list.Items {
ki.gatherPersistentVolumeClaim(pvc, acc)
}
}
func (ki *KubernetesInventory) gatherPersistentVolumeClaim(pvc corev1.PersistentVolumeClaim, acc telegraf.Accumulator) {
phaseType := 3
switch strings.ToLower(string(pvc.Status.Phase)) {
case "bound":
phaseType = 0
case "lost":
phaseType = 1
case "pending":
phaseType = 2
}
fields := map[string]interface{}{
"phase_type": phaseType,
}
tags := map[string]string{
"pvc_name": pvc.Name,
"namespace": pvc.Namespace,
"phase": string(pvc.Status.Phase),
"storageclass": *pvc.Spec.StorageClassName,
}
if pvc.Spec.Selector != nil {
for key, val := range pvc.Spec.Selector.MatchLabels {
if ki.selectorFilter.Match(key) {
tags["selector_"+key] = val
}
}
}
acc.AddFields(persistentVolumeClaimMeasurement, fields, tags)
}