FWIW: sysload shows available RAM and swap

Want something added? Ask for it here.
Post Reply
User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

FWIW: sysload shows available RAM and swap

Post by sander »

I've added a few lines to sabnzbd/misc.py of SAB 0.7.4, and now the sysload info bar also shows available RAM and swap. Examples:

My laptop:
Sysload: 0.21 | 0.27 | 0.35 | SABnzbd V=2580M R=51M | System RAM=3753M Swap=4766M
My VPS:
Sysload: 0.01 | 0.21 | 0.52 | SABnzbd V=392M R=31M | System RAM=237M Swap=511M
My Raspi:
Sysload: 2.03 | 1.45 | 1.22 | SABnzbd V=186M R=20M | System RAM=184M Swap=99M
This should be helpful in cases where users complain about SAB not performing. For example, not having swap on a low-RAM system is killing.

Note: Linux only

misc.py changes:

At the top:

Code: Select all

def myram():
	try:
		t = open('/proc/meminfo')
		v = t.read().split()
		t.close()
		#print "v is", v[1]
		myram = int(v[1]) / 1024
		return myram
	except:
		return None

def myswap():
	swap=0
	try:
		t = open('/proc/swaps')
		for thisline in t.readlines():
			#print thisline.rstrip()
			if thisline.startswith('/'):
				swap = swap + int(thisline.split()[2]) / 1024
		t.close()
		return swap
	except:
		return 0	# Not sure what happens on a Linux without swap: is there a /proc/swaps ?

availableram = myram()
availableswap = myswap()
and

Code: Select all

def memory_usage():
    try:
        # Probably only works on Linux because it uses /proc/<pid>/statm
        t = open('/proc/%d/statm' % os.getpid())
        v = t.read().split()
        t.close()
        virt = int(_PAGE_SIZE * int(v[0]) / MEBI)
        res = int(_PAGE_SIZE * int(v[1]) / MEBI)
        return "SABnzbd V=%sM R=%sM | System RAM=%sM Swap=%sM" % (virt, res, availableram, availableswap)
    except:
        return None
Post Reply