Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
53
plugins/inputs/kube_inventory/persistentvolumeclaim.go
Normal file
53
plugins/inputs/kube_inventory/persistentvolumeclaim.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
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),
|
||||
}
|
||||
if pvc.Spec.StorageClassName != nil {
|
||||
tags["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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue