kubernetes / kube-state-metrics

Add-on agent to generate and expose cluster-level metrics.
https://kubernetes.io/docs/concepts/cluster-administration/kube-state-metrics/
Apache License 2.0
5.43k stars 2.02k forks source link

Count volumes attached to a node #2501

Open thommeo opened 1 month ago

thommeo commented 1 month ago

What would you like to be added:

  1. A gauge metric reflecting number of the persistent volumes attached to a node.

Why is this needed:

The number of volumes that can be attached to a Node is limited.

Event with higher limits e.g. with Google we can still reach them. So monitoring the number of volumes attached per node and number of volumes that can be attached per node is essential to scale out when it's required.

Describe the solution you'd like

Here is how I tried to tackle this, but apparently it is not possible and will not be possible to create custom resource states on the core objects. So this is NOT working:

        kind: CustomResourceStateMetrics
        spec:
          resources:
            - groupVersionKind:
                group: ""
                kind: Node
                version: v1
              labelsFromPath:
                node: [metadata, name]
              metrics:
                - name: node_volumes_attached_count
                  help: Number of volumes attached to the node
                  type: Gauge
                  gauge:
                    path: [status, volumesAttached]
                    valueFrom:
                      count: {}
                - name: node_volumes_in_use_count
                  help: Number of volumes in use on the node
                  type: Gauge
                  gauge:
                    path: [status, volumesInUse]
                    valueFrom:
                      count: {}

I am not sure if this max volume limit is exposed to Kubernetes by the vendors in any way, but we definitely can count the attached volumes. Knowing the given provider limitations, we can come up with the alerting strategy based on node labels and the count of the volumes that are currently attached.

dgrisonnet commented 1 month ago

/triage accepted /assign