Created
November 13, 2012 18:16
-
-
Save jamesob/4067424 to your computer and use it in GitHub Desktop.
Df check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Script that checks to see that disk usage is below a certain threshold. | |
Designed to be invoked by cron. | |
""" | |
from sh import df | |
import re | |
UHOH_THRESHOLD = 90 # percentage usage that triggers an alarm | |
def find_root_usage(): | |
"""Return percentage of disk usage at mountpoint / as an int.""" | |
root_line = df('/').stdout.split('\n')[-1] | |
match = re.search(r'(\d+)%', root_line) | |
return int(match.group(1)) | |
usage_perc = find_root_usage() | |
if usage_perc >= UHOH_THRESHOLD: | |
print "Usage of / is %d percent." % usage_perc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment