Monitoring free disk space

monitoring of the pi park

What happened before

Previous post was about: * get an alert when a raspberry pi can not be reached * get an alert when a process is not active * get an alert when a logfile contains error or is supposed to have a last modification date of yesterday, but it is older.

It turns out, that sometimes the free disk space becomes less and less. And then it is 100% full. I need an alert for that.

Python script

import subprocess

#configurable parameters
perc = "85%"
host = "rasV"

p = subprocess.Popen("df -h | grep '/dev/root'", stdout=subprocess.PIPE, shell=True)
dfdata = p.communicate()
#print(dfdata[0])
#dfdata is a tuple, we only need first item of the tuple
#content of the first item of the tpuple is converted to list
dfdatalist = dfdata[0].split()
#iterate over the items in the list
for i in dfdatalist:
     #print(i)
     #we are only interested in the item with the %-sign
     if i.find("%")> -1:
          if i > perc:
             alert= host + " /dev/root > " + perc
             subprocess.Popen(["sudo","python3","/home/pi/scripts/telegram.py",alert])
comments powered by Disqus