migrated and upgraded to 0.5.2, lost system averages.

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
Nordmann
Newbie
Newbie
Posts: 10
Joined: March 17th, 2010, 9:36 am

migrated and upgraded to 0.5.2, lost system averages.

Post 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? 
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: migrated and upgraded to 0.5.2, lost system averages.

Post 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 ""
Nordmann
Newbie
Newbie
Posts: 10
Joined: March 17th, 2010, 9:36 am

Re: migrated and upgraded to 0.5.2, lost system averages.

Post by Nordmann »

That turned out to be exactly the case.
Thank you for pointing me in the correct direction Shypike :D

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. :o

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
Image
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: migrated and upgraded to 0.5.2, lost system averages.

Post by shypike »

It may work, but running an external process each time is a bit costly...
grump
Newbie
Newbie
Posts: 1
Joined: May 19th, 2010, 2:41 am

Re: migrated and upgraded to 0.5.2, lost system averages.

Post 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  :D

Code: Select all

import os
def loadavg():
    return '%.2f, %.2f, %.2f' % os.getloadavg()
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: migrated and upgraded to 0.5.2, lost system averages.

Post 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...
Nordmann
Newbie
Newbie
Posts: 10
Joined: March 17th, 2010, 9:36 am

Re: migrated and upgraded to 0.5.2, lost system averages.

Post 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!  ;D



Grump, you git!  you came here from the FreeBSD forum to steal my grand finale! lol!!
Post Reply