forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistentvolume.go
47 lines (41 loc) · 1018 Bytes
/
persistentvolume.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
package kube_inventory
import (
"context"
"strings"
corev1 "k8s.io/api/core/v1"
"github.com/influxdata/telegraf"
)
func collectPersistentVolumes(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getPersistentVolumes(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, pv := range list.Items {
ki.gatherPersistentVolume(pv, acc)
}
}
func (ki *KubernetesInventory) gatherPersistentVolume(pv corev1.PersistentVolume, acc telegraf.Accumulator) {
phaseType := 5
switch strings.ToLower(string(pv.Status.Phase)) {
case "bound":
phaseType = 0
case "failed":
phaseType = 1
case "pending":
phaseType = 2
case "released":
phaseType = 3
case "available":
phaseType = 4
}
fields := map[string]interface{}{
"phase_type": phaseType,
}
tags := map[string]string{
"pv_name": pv.Name,
"phase": string(pv.Status.Phase),
"storageclass": pv.Spec.StorageClassName,
}
acc.AddFields(persistentVolumeMeasurement, fields, tags)
}