Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement linux load average #384

Closed
giampaolo opened this issue May 23, 2014 · 17 comments
Closed

Implement linux load average #384

giampaolo opened this issue May 23, 2014 · 17 comments

Comments

@giampaolo
Copy link
Owner

From skolpat...@gmail.com on May 22, 2013 22:56:57

Proposal  
Implement linux load average in psutil 

On what platforms would this be available?  
Linux 

Proposed API  
Use getloadavg() perhaps? 

Are there existent implementations we can use as an example?  


Please provide any additional information below.  
If you guys think its feasible to present linux load average in psutil, I'd be 
interested in working on making this happen.

Original issue: http://code.google.com/p/psutil/issues/detail?id=384

@giampaolo
Copy link
Owner Author

From g.rodola on May 22, 2013 14:19:26

You can already do that with stdlib's os.getloadavg().

Status: WontFix

@Smankusors
Copy link

Smankusors commented Jul 8, 2020

@giampaolo hmm what if stdlib/libc doesn't have getloadavg? For example some libc on Android doesn't implement this.

You can easily reproduce this using Termux app (available on Google Play).

Edit: if SELinux is enforced, you need root to read /proc/loadavg

@giampaolo
Copy link
Owner Author

what if stdlib/libc doesn't have getloadavg?

In that case psutil.getloadavg() is not available. From source code:

if hasattr(os, "getloadavg") or hasattr(_psplatform, "getloadavg"):
    # Perform this hasattr check once on import time to either use the
    # platform based code or proxy straight from the os module.
    if hasattr(os, "getloadavg"):
        getloadavg = os.getloadavg
    else:
        getloadavg = _psplatform.getloadavg

    __all__.append("getloadavg")

@Smankusors
Copy link

And yeah that's error I got... 😅

But there's some alternative without root, that you can get load average from /system/bin/uptime instead 🤔

@giampaolo
Copy link
Owner Author

giampaolo commented Jul 8, 2020

For example some libc on Android doesn't implement this.

Does psutil work on Android?

@Smankusors
Copy link

For example some libc on Android doesn't implement this.

Does psutil work on Android?

Hmm how to test it all? I just do import psutil and it's working, not throwing any exception. But when I need getloadavg and I got this :

AttributeError: module 'psutil' has no attribute 'getloadavg'

(This is expected from psutil code you mentioned before)

@giampaolo
Copy link
Owner Author

python3 -m psutil.tests

@Smankusors
Copy link

Ok I run it on my 2 devices (both non-root and root shell), but the errors seems incosistent across devices. Both of this two devices are custom ROM too.

psutil_tab.txt
psutil_xsp.txt
psutil_root_tab.txt
psutil_root_xsp.txt

@giampaolo
Copy link
Owner Author

Considering psutil was never developed on Android I'd say that's not bad at all.

@giampaolo
Copy link
Owner Author

Does androind have /proc/loadavg?

@Smankusors
Copy link

Considering psutil was never developed on Android I'd say that's not bad at all.

it could be worse if it's on OEM/non-custom ROM 😉

Does androind have /proc/loadavg?

It looks like android have? I don't know in non custom ROM because of SELinux being enforced 😅

But 2 of my devices which is custom ROM does have that /proc/loadavg

@Smankusors
Copy link

I could do PR for this though. But I will get the loadavg by getting output of uptime command. 🤔

@giampaolo
Copy link
Owner Author

giampaolo commented Jul 9, 2020

Whats the output of cat /proc/loadavg? It's weird the file is there but glibc does not expose the syscall. Can you determine what glibc version is installed? Manual says 2.19 is required.

@Smankusors
Copy link

Smankusors commented Jul 9, 2020

cat /proc/loadavg, it's weird the file is there but glibc does not expose the syscall. Can you determine what glibc version is installed? Manual says 2.19 is required.

huh? no. Android doesn't use glibc, but Bionic. It's a different implementation, that's why sometimes there's libc function that's missing on Android. 😥

Even though you can read /proc/loadavg on Android, it still needs root access (or SELinux permissive/disabled). But using uptime works without root. 🤔

edit: the content of /proc/loadavg is pretty similiar with other Linux systems. Mine is 26.04 24.78 24.46 6/1380 976. And it's very common Android have very high load avg though.

@giampaolo
Copy link
Owner Author

I don't think parsing uptime is worth it. I prefer to keep things simple. You can easily do it in your own code though.

@Smankusors
Copy link

that's fine. Thanks for the response 😉

hmm.... is there possibility that uptime have output variation/inconsistent output across devices and operating system? 🤔

@giampaolo
Copy link
Owner Author

giampaolo commented Jul 9, 2020

I don't know. It's the main reason why I don't think it's worth it to put it in psutil. =)

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

No branches or pull requests

2 participants