Automatically monitor free space
Is there a way to have the servers send me an email when any of the partitions drop below a certain amount of free disk space?
|
If you don't need real time, you can design a script that will parse the output of df, and check if the free space is lesser than a given number or percentage, and if affirmative mail you. Then you can put it as a cron job.
You could as well mount the remote drive via nfs, sshfs, samba or whatever fits you, and just monitor it locally with gkrellm, conky or something else. |
Here is one idea that may get going in the right direction. Create a script similar to the following listing:
#!/bin/bash EMAIL=user@example.com SUBJECT="WARNING: Disk space low" df -h | sed 's/%//' | awk '{if ($5 > 19) print $0 }' | mail -s "$SUBJECT" $EMAIL Change the 19 in the awk statement to be your threshold or upper limit. I used 19 to test an existing partition. Then if this works for you, just setup a cron job to run as often as you need. Regards, Fordeck |
What's the 19 signify? percentage free space or MB or something?
|
be forewarned that if you use a script on the machine to check for diskspace using a cron job that if the disk space fills up in between cron jobs and the partition is the / partition you will not get an alert. Ive had instances where the / filled up and the script apparently needs some tmp space to execute the script and if there is no space left the script will not run. If you have more than one server you can either run a cron job from another server, setting up ssh keys of course or you can use something like nagios to monitor disk space.
|
I think my / have a good amount of space where I won't have to worry about them filling up. I'm more concerned with the couple data partitions I have. but that's good to know though, I never thought of that.
|
Here is an example of the output of the df -h command:
Code:
[user@fs2 ~]$ df -h $5 > 19 Where 19 is the percentage that I chose as my upper limit for the sake of testing. Because the /dev/sda6 which is mounted on / is at 23% it will trigger an email. You of course will have a number that you want to use for that upper limit rather than 19. The sed command simply removes the % symbol and $5 simply refers to the 5th column of data to see if it is greater than 19. Code:
#!/bin/bash Regards, Fordeck |
OK, I can actually make sense of what that line does now, thanks!
|
Now I just gotta figure out what to do to setup email on the server haha.
|
all you should need is sendmail and to make sure its running.
|
thanks!
|
To see if sendmail is installed you could run the following command:
rpm -qa | grep sendmail If it is installed you should see something similar to the this: Code:
[user@fs2 ~]# rpm -qa | grep sendmail chkconfig --list | grep sendmail This will show output similar to: Code:
[user@fs2 ~]# chkconfig --list | grep sendmail Regards, Fordeck |
thanks, i'll check it out
|
All times are GMT -5. The time now is 09:19 PM. |