I am currently working on an application to use my RPi to monitor what is happening in my flat (temperature, ...) but I also want to use this application to monitor how fine my RPi is going.

As it might be of interest for some of you I decided to share some code to monitor the CPU, RAM and disk of the RPi (I have a model B, 512 Mb, Raspbian and use python 2.7 + pygame for the interface).

First the functions that can allow you to retrieve CPU information (temperature + usage), RAM info (total, usage) and disk usage (total, usage). The comments generally explain quite well the functions that actually rely on Unix commands launched from Python.

I used these chunks of codes for my interface and, so far, it works nicely and gives this kind of results: see image. The design still sucks (icons are not very explicit) but I will work on this later.

If you have any questions or want to share your tips to monitor your RPi activity using Python feel free to use this topic. By the way, the code presented here is of course free to be used. I do not guarantee it will work on every RPi but I hope so. =)

Final comment: I didn't know where to post this topic. Please move it if you think it is better suited in an other forum.

@PhJulien: You are mostly reinventing the `psutil` module which can be installed with ``sudo apt-get python-psutil``. It is cross platform, so code using it also works on Windows, MacOSX, and FreeBSD. That module can even examine single processes for CPU and memory usage, asked for subprocesses and threads, open files, network connections, I/O amount, …

This leaves the CPU temperature as the only Raspi specific value. The `subprocess` module is meant to replace all the other ways to call external programs.

thanks for the pointer, I didn't know this library. I looked for something similar but, surprisingly, did not come across this one. Maybe because at the beginning I was mostly looking for how to monitor CPU temperature, which is specific to the RPi...

Python 3.2.3 (default, Jul 6 2012, 13:39:51)
[/quote]
The trace you put up here earlier was for python 2.7.
Try this again by running python2.7 instead. It looks like python3.2.x is your default for when running your script, and I bet psutils is actually only installed in python 2.7
Cheers
Tim