diff --git a/docs/persistentvolume-metrics.md b/docs/persistentvolume-metrics.md
index 9b3d8ce114..898988de16 100644
--- a/docs/persistentvolume-metrics.md
+++ b/docs/persistentvolume-metrics.md
@@ -1,7 +1,7 @@
# PersistentVolume Metrics
| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status |
-| ---------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
+|------------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
| kube_persistentvolume_annotations | Gauge | Kubernetes annotations converted to Prometheus labels controlled via [--metric-annotations-allowlist](./cli-arguments.md) | | `persistentvolume`=<persistentvolume-name>
`annotation_PERSISTENTVOLUME_ANNOTATION`=<PERSISTENTVOLUME_ANNOTATION> | EXPERIMENTAL |
| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=<pv-name> | STABLE |
| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=<pv-name>
`phase`=<Bound\|Failed\|Pending\|Available\|Released> | STABLE |
@@ -10,6 +10,7 @@
| kube_persistentvolume_info | Gauge | Information about Persistent Volumes | | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`host_path`=<path-of-a-host-volume>
`host_path_type`=<host-mount-type>
`ebs_volume_id`=<ebs-volume-id>
`azure_disk_name`=<azure-disk-name>
`fc_wwids`=<fc-wwids-comma-separated>
`fc_lun`=<fc-lun>
`fc_target_wwns`=<fc-target-wwns-comma-separated>
`iscsi_target_portal`=<iscsi-target-portal>
`iscsi_iqn`=<iscsi-iqn>
`iscsi_lun`=<iscsi-lun>
`iscsi_initiator_name`=<iscsi-initiator-name>
`local_path`=<path-of-a-local-volume>
`local_fs`=<local-volume-fs-type>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path>
`csi_driver`=<csi-driver>
`csi_volume_handle`=<csi-volume-handle> | STABLE |
| kube_persistentvolume_created | Gauge | Unix creation timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL |
| kube_persistentvolume_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL |
+| kube_persistentvolume_csi_attributes | Gauge | CSI attributes of the Persistent Volume. | | `persistentvolume`=<persistentvolume-name>
`csi_mounter`=<csi-mounter>
`csi_map_options`=<csi-map-options> | EXPERIMENTAL |
## Useful metrics queries
diff --git a/internal/store/persistentvolume.go b/internal/store/persistentvolume.go
index bd534ea87b..a924d39257 100644
--- a/internal/store/persistentvolume.go
+++ b/internal/store/persistentvolume.go
@@ -43,6 +43,9 @@ var (
descPersistentVolumeLabelsName = "kube_persistentvolume_labels"
descPersistentVolumeLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descPersistentVolumeLabelsDefaultLabels = []string{"persistentvolume"}
+
+ descPersistentVolumeCSIAttributesName = "kube_persistentvolume_csi_attributes"
+ descPersistentVolumeCSIAttributesHelp = "CSI attributes of the Persistent Volume."
)
func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
@@ -349,6 +352,45 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
}
}),
),
+ *generator.NewOptInFamilyGenerator(
+ descPersistentVolumeCSIAttributesName,
+ descPersistentVolumeCSIAttributesHelp,
+ metric.Gauge,
+ basemetrics.ALPHA,
+ "",
+ wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family {
+ if p.Spec.CSI == nil {
+ return &metric.Family{
+ Metrics: []*metric.Metric{},
+ }
+ }
+
+ var csiMounter, csiMapOptions string
+ for k, v := range p.Spec.PersistentVolumeSource.CSI.VolumeAttributes {
+ if k == "mapOptions" {
+ csiMapOptions = v
+ } else if k == "mounter" {
+ csiMounter = v
+ }
+ }
+
+ return &metric.Family{
+ Metrics: []*metric.Metric{
+ {
+ LabelKeys: []string{
+ "csi_mounter",
+ "csi_map_options",
+ },
+ LabelValues: []string{
+ csiMounter,
+ csiMapOptions,
+ },
+ Value: 1,
+ },
+ },
+ }
+ }),
+ ),
}
}
diff --git a/internal/store/persistentvolume_test.go b/internal/store/persistentvolume_test.go
index 4ff4750d72..81670b7a60 100644
--- a/internal/store/persistentvolume_test.go
+++ b/internal/store/persistentvolume_test.go
@@ -393,6 +393,10 @@ func TestPersistentVolumeStore(t *testing.T) {
CSI: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-handle",
+ VolumeAttributes: map[string]string{
+ "mounter": "rbd",
+ "mapOptions": "krbd:rxbounce",
+ },
},
},
},
@@ -697,6 +701,52 @@ func TestPersistentVolumeStore(t *testing.T) {
`,
MetricNames: []string{"kube_persistentvolume_deletion_timestamp"},
},
+ {
+ Obj: &v1.PersistentVolume{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-pv-available",
+ },
+ Spec: v1.PersistentVolumeSpec{
+ PersistentVolumeSource: v1.PersistentVolumeSource{
+ CSI: &v1.CSIPersistentVolumeSource{
+ Driver: "test-driver",
+ VolumeHandle: "test-volume-handle",
+ },
+ },
+ },
+ },
+ Want: `
+ # HELP kube_persistentvolume_csi_attributes CSI attributes of the Persistent Volume.
+ # TYPE kube_persistentvolume_csi_attributes gauge
+ kube_persistentvolume_csi_attributes{persistentvolume="test-pv-available",csi_mounter="",csi_map_options=""} 1
+ `,
+ MetricNames: []string{"kube_persistentvolume_csi_attributes"},
+ },
+ {
+ Obj: &v1.PersistentVolume{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-pv-available",
+ },
+ Spec: v1.PersistentVolumeSpec{
+ PersistentVolumeSource: v1.PersistentVolumeSource{
+ CSI: &v1.CSIPersistentVolumeSource{
+ Driver: "test-driver",
+ VolumeHandle: "test-volume-handle",
+ VolumeAttributes: map[string]string{
+ "mounter": "rbd",
+ "mapOptions": "krbd:rxbounce",
+ },
+ },
+ },
+ },
+ },
+ Want: `
+ # HELP kube_persistentvolume_csi_attributes CSI attributes of the Persistent Volume.
+ # TYPE kube_persistentvolume_csi_attributes gauge
+ kube_persistentvolume_csi_attributes{persistentvolume="test-pv-available",csi_mounter="rbd",csi_map_options="krbd:rxbounce"} 1
+ `,
+ MetricNames: []string{"kube_persistentvolume_csi_attributes"},
+ },
}
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(persistentVolumeMetricFamilies(c.AllowAnnotationsList, c.AllowLabelsList))