5
votes

I've created a persistent disk in Google Compute Engine and attached it to an instance. What I am wondering however, is how can I monitor the free space on the disk? Can't see it either in the Google Cloud Console or from the gcloud tool.

3

3 Answers

3
votes

If you cannot use the Stackdriver Monitoring Agent, an alternative will be to use the gcloud command line tool to write to cloud logging.

Note that this is using a beta command, so may change in the future.

First, ensure that the logging beta commands are installed by typing:

gcloud beta logging

If it does not work, you can install with:

sudo gcloud components install beta

On your instance setup a cron job to run some script according to a schedule:

sudo crontab -e

Go to the bottom of the file and enter:

0 * * * * gcloud beta logging write disk_usage $(df / |  awk '{print $5}' | cut -d '%' -f 1 | tail -n 1)

This will run the command gcloud beta logging write disk_usage $(df / | awk '{print $5}' | cut -d '%' -f 1 | tail -n 1) once an hour, which will write the % of used space to the disk_usage log.

Next go to Logging and from the first drop down choose Global and from the second choose disk_space.

It is not a perfect solution, but it will work.

6
votes

You can use (Google) Stackdriver monitoring: https://cloud.google.com/monitoring/

If you install the Monitoring Agent on your instance, the Volume Free Space (Agent) metric will then become available.

You can setup an alert to notify you at significant levels.

Note that the Agent is now only available with a Premium subscription.

4
votes

If you have GCP VMs then you can monitor using the stackdriver agent and you'll need to add the following alert policy. It won't appear in the console until after a few hours of collecting info from your agents:

volume usage (agent)

enter image description here