Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check total memory and if used more than 3.0GB and make desktop notification with programs which use more than 2.0GB
#!/usr/bin/env python2
import commands, pynotify, sys, os, time
while 1:
lines = commands.getoutput('sudo').split('\n')
total = [float(str(l).split(" ")[-2]) for l in lines if l.startswith(" ") and l.find("GiB")]
progs = [str(l).split("=")[1].strip().split(" ") for l in lines if l.find("GiB") != -1 and not l.startswith(" ")]
for prog in progs:
if float(prog[0]) > 2.0 and total[0] > 3.0:
pynotify.init("Memory usage notification")
notification = pynotify.Notification(prog[0] + " " + prog[1].replace('\t', ' '), "")

This comment has been minimized.

Copy link
Owner Author

@marcellmars marcellmars commented Feb 19, 2012

i will never learn how to use web broswer with just few tabs. this is a little daemon which notifies me when things get close to screwed up ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment