i have an virtual machine (which am using as build server) which disk gets piled up frequently and am working on fixing that, mean while am looking for options to setup an alert to be fired when my disk space gets high.
i checked the available metrics under monitoring but could only find "disk write bytes" and "disk read bytes" which are not helpful for me.
i will need help on setting a disk space alert to be sent to my email.
Any help on this is really appreciated.
i will need help on setting a disk space alert to be sent to my email.
For now, Azure does not support monitor Azure VM disk space, we can use shell
or PowerShell
to monitor VM disk space and send email to you.
Here a example about Linux VM(ubuntu), we can create a sample.sh
then add it to cron
.
sample.sh:
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' youremail@domainname.com << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
Add it to cron
, add it to crontab
:
*/60 * * * * /home/jason/sample.sh
Note:
we should install mail on this VM with this script:apt install mailutils
.
By the way, if you don't want to install mail on your VM and don't want to use VM to monitor itself, we can create another VM and install Zabbix
or other monitor tools to monitor Azure VMs disks space.
You can use Azure OMS. There is a example how to use Azure OMS to monitor free disk.