Question

How can I get how much disk space is available on my Droplet using API

Posted February 15, 2020 769 views
API

is there any method that i can get the size left on my Droplet using API

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

I don’t think that this is yet possible via the API directly. There is already a similar idea shared here that you could vote for:

In the meantime, I could suggest a couple of alternatives:

  • You could set up Monitoring Alerts so that you get a notification in case that your Disk usage is higher than let’s say 70%, for more information on how to do that you could have a look at the official documentation here:

https://www.digitalocean.com/docs/monitoring/quickstart/#create-alert-policies

  • You could use an SSH command and run a check remotely, it would look something like this:
ssh your_user@your_droplet_ip df -h

The output that you would get would look something like this:

Filesystem      Size  Used Avail Use% Mounted on
udev            478M     0  478M   0% /dev
tmpfs            99M  920K   98M   1% /run
/dev/vda1        25G   16G  9.0G  63% /
...

If you have multiple droplets you could use a loop to go through all droplets and run the command on each, here’s an example script:

#!/bin/bash

# List of your Droplet IPs separated by space
list_of_droplets="droplet_ip_1 droplet_ip_2 droplet_ip_3"

for droplet in $list_of_droplets ; do
    echo "Disk Usage for ${droplet}"
    ssh your_user@${droplet} df -h
done

You could add your SSH key to each Droplet and that way you would not have to type your password each time.

  • Another solution would be to use a monitoring tool like Nginx or NewRelic but this requires more upfront configuration

Hope that this helps!
Regards,
Bobby

Submit an Answer