Skip to content

Instantly share code, notes, and snippets.

@jamesob
Created November 13, 2012 18:16
Show Gist options
  • Save jamesob/4067424 to your computer and use it in GitHub Desktop.
Save jamesob/4067424 to your computer and use it in GitHub Desktop.
Df check
#!/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