Page 1 of 1
migrated and upgraded to 0.5.2, lost system averages.
Posted: May 17th, 2010, 11:05 am
by Nordmann
hiyas
I've been running Sab 0.5 on a opensuse machine, and I have recently migrated to FreeBSD8.0 and upgraded sabnzbs to 0.5.2 at the same time.
Now, I don't know if it because of FreeBSD, or the fact that I copied the .sabnzb folder (to keep the history) from opensuse and put it in the appropriate user's folder which runs sabnzb, but after the migration I have lost the sysload (system averages) that where located at the lower right corner, next to weekly /monthly average data transfer.
I kinda miss that.. anyone know if I can get that back?
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 17th, 2010, 3:37 pm
by shypike
The most likely cause is that FreeBSD doesn't provide sysload in the way
SABnzbd expects it.
It expects the pseudo-file /proc/loadavg to contains the numbers.
This is the piece of code that does the work:
Code: Select all
def loadavg():
""" Return 1, 5 and 15 minute load average of host or "" if not supported
"""
try:
loadavgstr = open('/proc/loadavg', 'r').readline().strip()
except:
return ""
data = loadavgstr.split()
try:
a1, a5, a15 = map(float, data[:3])
return "%.2f, %.2f, %.2f" % (a1, a5, a15)
except:
return ""
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 18th, 2010, 6:32 am
by Nordmann
That turned out to be exactly the case.
Thank you for pointing me in the correct direction Shypike
Turns out that FreeBSD and the other BSD's have a very limited procfs that doesn't support loadavg. heck, the BSD people say it is such a big security risk they have turned it off, and FreeBSD is working on removing it in its entirety.
Anyways, I asked the clever heads a FreeBSD forum for a solution and they came up with this piece of code, which I put inside misc.py, replacing the old code.
Code: Select all
def loadavg():
command = ['sysctl', 'vm.loadavg']
try:
pipe = subprocess.Popen(command, stdout=subprocess.PIPE)
a1, a5, a15 = map(float, pipe.stdout.read().split(' ')[2:5])
return "%.2f, %.2f, %.2f" % (a1, a5, a15)
except:
return ""
As you can see, it works perfectly. this is during a forkbomb. hehehe
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 18th, 2010, 7:28 am
by shypike
It may work, but running an external process each time is a bit costly...
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 19th, 2010, 2:54 am
by grump
hey fellas, just thought it was worth mentioning here what was pointed out to me at the freebsd forums when i came up with that fix:
... the existence of os.getloadavg() ... which is a much better solution
Code: Select all
import os
def loadavg():
return '%.2f, %.2f, %.2f' % os.getloadavg()
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 19th, 2010, 5:13 am
by shypike
Thanks for the tip!
It's great when programming languages have rich libraries, it's still hard to find the function that you need.
Who would have thought this even existed...
Re: migrated and upgraded to 0.5.2, lost system averages.
Posted: May 19th, 2010, 10:12 am
by Nordmann
I didn't know, thats for sure! lol
I've replaced the entire loadavg section with just this
Code: Select all
def loadavg():
return "%.2f, %.2f, %.2f" % os.getloadavg()
and it works like a charm!
Grump, you git! you came here from the FreeBSD forum to steal my grand finale! lol!!