mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Moving to more accurate disk usage monitor.
This commit is contained in:
parent
a1e23eb8d5
commit
21e5da0ecf
1 changed files with 8 additions and 5 deletions
|
@ -3,25 +3,28 @@
|
|||
import sys
|
||||
sys.path.append('/srv/newsblur')
|
||||
|
||||
import subprocess
|
||||
import psutil
|
||||
import requests
|
||||
import settings
|
||||
import socket
|
||||
|
||||
def main():
|
||||
usage = psutil.disk_usage('/')
|
||||
df = subprocess.Popen(["df", "/"], stdout=subprocess.PIPE)
|
||||
output = df.communicate()[0]
|
||||
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
|
||||
hostname = socket.gethostname()
|
||||
|
||||
if usage.percent > 95:
|
||||
if int(percent) > 95:
|
||||
requests.post(
|
||||
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
|
||||
auth=("api", settings.MAILGUN_ACCESS_KEY),
|
||||
data={"from": "NewsBlur Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
|
||||
"to": [settings.ADMINS[0][1]],
|
||||
"subject": "%s hit %s%% disk usage!" % (hostname, usage.percent),
|
||||
"text": "Usage on %s: %s" % (hostname, usage)})
|
||||
"subject": "%s hit %s%% disk usage!" % (hostname, int(percent)),
|
||||
"text": "Usage on %s: %s" % (hostname, output)})
|
||||
else:
|
||||
print " ---> Disk usage is fine: %s / %s%% used" % (hostname, usage.percent)
|
||||
print " ---> Disk usage is fine: %s / %s%% used" % (hostname, int(percent))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue