How to monitor disk usage of persistent volumes?

Cemal Unal picture Cemal Unal · Apr 29, 2019 · Viewed 7.6k times · Source

I want to monitor disk usages of persistent volumes in the cluster. I am using CoreOS Kube Prometheus. A dashboard is trying to query with a metric called kubelet_volume_stats_capacity_bytes which is not available anymore with Kubernetes versions starting from v1.12.

I am using Kubernetes version v1.13.4 and hostpath-provisioner to provision volumes based on persistent volume claim. I want to access current disk usage metrics for each persistent volume.

  • kube_persistentvolumeclaim_resource_requests_storage_bytes is available but it shows only the persistent claim request in bytes

  • container_fs_usage_bytes is not fully covers my problem.

Answer

Malgorzata picture Malgorzata · Jun 18, 2019

Yes, in newest version of Kubernetes you cannot monitor metric such as kubelet_volume_stats_capacity_bytes, but there are some workarounds. Unfortunately this is a bit fragmented in Kubernetes today. PVCs may have capacity and usage metrics, depending on the volume provider, and it seems that any CSI based volume doesn't have these at all. We can do this on a best effort basis butit is simple to quickly hit cases where these metrics are not available.

First, just simply write your own script which will be every time values of metric like container_fs_usage_bytes are gathered will be count difference between capacity before measurement and container usage in bytes (metric will container_fs_usage_bytes be helpful).

Prometheus is quite popular solution but to monitor capacity especially disk usage you can use Heapster, now he is about to "retire", but just for this special case you can use it, but you will have to implement script too. Take look on repository: heapster-memory

"res.Containers = append(res.Containers, metrics.ContainerMetrics{Name: c.Name, Usage: usage})"

I hope it helps.