How to calculate days until volume (or disk) is full

I don’t have a problem, I’d just like to share a query I have that allows you to calculate the number of days (or with tweaking, hours) until a Kubernetes volume is full. I think this is extremely useful for alerting purposes, because if you have a volume at 96% that adds a percentage point every 2 weeks, you don’t want to be alerted when it passed the 90% threshold since you still have about 20 weeks until it fills up).

The estimate will range up to a year. You can adjust the decimal argument in clamp_min() to increase/decrease the maximum value for the prediction. The query is actually for 99% instead of 100% to give you just that little bit more wiggle room.

FROM K8sVolumeSample 
SELECT min(fsAvailableBytes / 1024 / 1024 / 1024) as 'GiB Free',
  clamp_min(
    (100 - 1 - stddev(fsUsedPercent) - max(fsUsedPercent))
      /
    clamp_min(
      deriv(fsUsedPercent, 1 days)
    ,0.00000313)
  ,0) as 'Days until full'
WHERE fsAvailableBytes > 0
AND volumeName NOT LIKE '%token%'
FACET pvcName SINCE 1 day ago
LIMIT MAX
8 Likes

Hi @tyzbit - That is useful. Would you mind posting this in the NRQL library?

1 Like

Hi @tyzbit,

Welcome and thank you for sharing this with the Explorers Hub! I’m certain other members of the community will find this quite helpful :slightly_smiling_face:

Love the creativity @tyzbit

Hi @tyzbit Could you please share what is the calculation behind decimal value 0.00000313

It caps the upper limit of the estimate at about a year. Otherwise we would be dealing with infinities.

1 Like