Visualising core load on the Pi 2

Since we released Raspberry Pi 2 back in February, a lot of you have been asking questions about how work gets divided between the four cores. David (what’s your last name, David? Let us know and I’ll update this post) in Cambridge has written a remote CPU-monitoring webserver, which outputs a nice scrolling graph of CPU load on all four cores onto a webpage, so you can view it remotely while your Pi 2 works, along with CPU temperature.

CPU usage

The monitoring software itself is lightweight, so it shouldn’t be a big consumer of resources on your Pi – the Pi’s sending a series of numbers representing load, and all the heavy lifting, turning it into visual data, is being done in Javascript by the browser on whatever machine you’re viewing it on. Here are the results, running on a simulated iPhone 4s.

This is very easy to set up; everything’s embedded in the executable, so all you have to do is to run the program. You’ll find full instructions and code in Dave’s GitHub repo here – if you already have another webserver running on your Pi you may need to change ports, but that aside, this is an absolute doddle to run.

Let us know if you have a play; we’d be interested to learn about what you find!

 

24 comments

Archisman Panigrahi avatar

Can this be embedded into the original LXDE interface of Raspbian? It shows all cores in a single graph.

Archisman Panigrahi avatar

How does rCPU actually work? Does it execute the commands in C and then dynamically edits the HTML file?

Leo White avatar

It looks like the rCPU code allows a browser to request the current state of the CPUs as a JSON file.

The web browser then calls that every second and creates the graph (So rCPU only keeps the ‘current’ data and not the historic data). So the html isn’t editted at all, the browser just makes use of Javascript and the DOM to dynamically update the graphs.

Liz Upton avatar

Exactly – Archisman, if you go and have a look at the GitHub repo that’s linked in the post, you should be able to follow what’s going on there.

Eric Olson avatar

It would appear the embedded webserver has code that will attempt to read an unlimited amount of data from a socket and store it in memory. The memory is allocated using realloc without any error checks. This is not something I would want accessible on the public internet. While the code looks straight-forward and otherwise well written, please be careful when using or repurposing this project for something else.

Dex Muir avatar

Great work! Can it be re-purposed to show Network usage? There’s a lack of this in Raspbian (on a B, and I suspect also on a 2), and this by browser or stand-alone app in the repo would do it. It would be even better if it could run in the Panel.
Hopeful…

Jim Manley avatar

If you want the Mother of All Browser-based Multiple-processor/core Monitoring Applications, look no further than Monitorix (http://www.Monitorix.org). The number of features is staggering and, given that it’s been around for 10 years, it has been highly optimized and bug-squashed. The totally free feature set includes:

Graphs:

– Raspberry Pi sensor statistics (raspberrypi.rrd)
— Up to 9 different clock frequency
— Core temperature
— Voltages

– System load average and usage (system.rrd)
— System load
— Active processes
— Memory allocation
– Global kernel usage (kern.rrd)
— Including user, nice, system, idle, i/o wait, irq, software irq, steal and guest
— Context switches
— Fork and vfork rates
— VFS usage (dentries, inodes and files)

– Per-processor kernel usage (proc.rrd)
Including user, nice, system, idle, i/o wait, irq, software irq, steal and guest
— Supports unlimited number of processors or cores
— Ability to define the number of graphs per row
— Ability to change the size of the graphs (there are already some predefined sizes)
— Ability to disable partial or completely the legend data

– Filesystem usage and I/O activity (fs.rrd)
— Unlimited number of filesystems graphs supported
— Up to 8 filesystems per graph
— Ability to hide the real name of each mount point (filesystem)
— Inode usage for each filesystem
— Disk I/O activity for each filesystem
— Time spent in disk I/O for each filesystem
— Disk sectors activity for each filesystem

– Network traffic and usage (net.rrd)
— Up to 10 network devices supported
— Including packet traffic and traffic error graphs

– Netstat statistics (netstat.rrd)
— Includes statistics for IPv4 and IPv6 connections
— All connection states are represented

– Libvirt statistics (libvirt.rrd)
— Unlimited number of virtual machines
— Up to 8 virtual machines per graph
— CPU time usage, memory usage, disk usage and network usage

– Process statistics (process.rrd)
— Unlimited number of user processes
— Up to 10 user processes per graph
— CPU usage, memory usage, disk usage and network usage
— Opened files, number of threads, number of voluntary and involuntary context switches and number of process instances

– System services demand (serv.rrd)
— Ability to toggle between (I)ncremental and (L)oad values
— Including (SSH, ProFTPD, Vsftpd, Pure-FTPd, Telnet, Samba, FAX, CUPS, Fail2ban, IMAP, POP3, SMTP, VirusMail and Spam)
— Supports xinetd, Sendmail, Postfix, Dovecot, UW-IMAP, Qpopper, Hylafax, MailScanner, Amavisd-new and CommuniGate logs
— Mail statistics (mail.rrd)
— Supported MTAs are Sendmail and Postfix
— Complete statistics including:
— Incoming connections
— Outgoing connections
— Rejected
— Delivered
— Received
— Bounced
— Discarded
— Held
— Forwarded
— Spam
— Virus
— Number of emails in queue
— Total size of all emails in queue
— Network traffic usage

– SPF results (smf-spf)

– Greylisting (milter-greylist)

– Network port traffic (port.rrd)
— Unlimited number of network ports supported
— Ability to select multiple protocol type for each port (tcp, udp, etc.)
— Supports incoming and outgoing connections
— It warns if a network port is not listening

– Users using the system (user.rrd)
— Supports SSH/Login/Telnet, Samba and Netatalk

– FTP statistics (ftp.rrd)
— Supports the log file format of ProFTPD, vsftpd and Pure-FTPd servers

– Apache statistics (apache.rrd)
— Including workers (busy and idle), CPU usage and requests/sec.
— Unlimited number of Apache servers supported

– Nginx statistics (nginx.rrd)
— Including connections (reading, writing, waiting), requests/sec and network traffic

– Lighttpd statistics (lighttpd.rrd)
— Including workers (busy and idle), network traffic and requests/sec
— Unlimited number of Lighttpd servers supported

– MySQL statistics (mysql.rrd)
— Query types per second:
— Select
— Commit
— Delete
— Insert
— Insert_Select
— Update
— Replace
— Replace_Select
— Rollback

— Percentage values of:
— Thread cache hit rate
— Query cache usage
— Connections usage
— Key buffer usage
— InnoDB buffer pool usage
— Number of opened tables and table locks waited per second
— Number of queries and slow queries per second
— Number of connections, abort clients and abort connects per second
— Network traffic
— Unlimited number of MySQL servers supported

– Varnish statistics (varnish.rrd)
— Workers and LRU objects statistics
— Backend usage
— Client connections
— Cache performance
— Objects
— Traffic

– Squid Proxy Web Cache statistics (squid.rrd)
— Up to 19 result and status codes supported
— Overall requests (client, server, etc.)
— Memory and disk storage usage
— IP cache use with requests, hits and misses
— Network protocols usage (HTTP, FTP, Gopher and WAIS)
— Client and server network traffic

– NFS server statistics (nfss.rrd)
— NFS v2, v3 and v4 supported
— Up to 30 defined requests supported
— Overall I/O bytes (read and written)
— Network layer usage (TCP, UDP and TCPConn)
— RPC usage
— Thread utilization
— Read cache usage
— File handle cache usage

– NFS client statistics (nfsc.rrd)
— NFS v2, v3 and v4 supported
— Up to 32 defined requests supported
— RPC usage

– BIND server statistics (bind.rrd)
— Unlimited number of BIND servers supported
— Incoming queries
— Outgoing queries (_default) view
— Name server statistics
— Resolver statistics (_default) view
— Cache DB RRsets (_default) view
— Memory usage
— Task manager

– NTP statistics (ntp.rrd)
— Unlimited number of NTP servers supported
— NTP timing
— Stratum level
— Reference Identifier and Kiss-o’-Death Codes

– Fail2ban statistics (fail2ban.rrd)
— Unlimited number of group of jails for monitoring
— Ability to define up to 9 jails per group or graph
— Ability to define a title for every group or graph of jails

– Icecast Streaming Media Server statistics (icecast.rrd)
— Unlimited number of Icecast servers supported
— Current listeners
— Bitrate

— Alternative PHP Cache statistics (phpapc.rrd)
— Unlimited number of web servers with PHP-APC installed
— Memory usage including fragmentation
— Hits and misses
— File cache information

– Memcached statistics (memcached.rrd)
— Unlimited number of servers with Memcached installed
— Hits and misses
— Cached usage and items in cache
— Objects I/O
— Connections
— Memcached network traffic

– APC UPS statistics (apcupsd.rrd)
— Unlimited number of APC UPS devices supported
— Line voltage with high and low transitions
— Temperatures with support for internal and ambient sensors
— Battery charge with load capacity and shutdown level
— Battery voltage and nominal
— Time left with shutdown level
— Line frequency

– Wowza Media Server (wowza.rrd)
— Unlimited number of Wowza servers supported
— Ability to define up to 8 applications per server

– Devices interrupt activity (int.rrd)
— APIC support with up to 256 different interrupts

– Verlihub statistics (verlihub.rrd)
— Connected users
— Total hub upload
— Total hub share

– Support for monitoring remote servers (Multihost)
— Unlimited number of remote servers
— Ability to define the number of graphs per row
— Ability to hide the real URL of each remote server
— Ability to create groups of remote servers
— Support for monitoring (as gateway) the Internet traffic of LAN devices
— Unlimited number of LAN devices (PC, printers, networks, etc.)
— Ability to define the number of graphs per row
— Ability to enable traffic monthly reports
— Ability to send individual traffic monthly reports
— Supported languages in reports: Catalan, German, English, Italian, Polish and Simplified Chinese
— Alert capabilities supported
— CPU load average alert
— Reallocated sector count alert
— Current pending sectors alert
— Root filesystem usage alert
— Delivered emails counter alert
— Mails queued counter alert
— Activated when it reaches or exceeds a threshold value for an specified amount of time
— Built-in HTTP server
— Basic access authentication supported
— IP address restriction with host_deny and host_allow options
— Configurable host address to bind to and network port to listen on
— The use of an external web server (like Apache, Nginx, etc.) is optional
— Complete email reporting mechanism of all graphs
— Ability to include additional configuration file(s)
— Ability to view statistics per day, week, month or year
— Ability to view statistics in graphs or in plain text tables
— Ability to zoom in any graph to see it in more detail
— Ability to show network metrics in MBytes/sec or Mbits/sec
— Ability to show temperatures in Celsius or in Fahrenheit
— Ability to configure the number of years of historical data (up to 5 years)
— Web interface offers minimal learning, ubiquitous access
— Configuration with only one text-plain file
— Silent mode to be able to retrieve the graphs from scripts

– Traffic statistics are stored in fixed-size databases (RRDtool)
— Perl language based (lightweight tool)
— Supported systems: GNU/Linux, FreeBSD, OpenBSD and NetBSD

Liz Upton avatar

When moderating this this morning, I saw the length before actually *reading* it and thought “I bet that’s a Jim comment”. Ten points for me.

Jim Manley avatar

Dang, and I was wearing my favo(u)rite sheep’s clothing (insert your favo(u)rite Woody Allen “Everything You Wanted to Know About Sex But Were Afraid to Ask” scene involving sheep here). I just can’t get _anything_ past you, can I? You have to admit, it _is_ a rather impressive feature set, though :D

Archisman Panigrahi avatar

Did you actually type this or just a copy-paste?

Luca Zenatti avatar

Another cool ( and lightweight ) project about system monitoring https://github.com/afaqurk/linux-dash .

R,
Luca

David avatar

Hi, David here, this one is my fault. I’m sorry to say that I quite like the anonymity of being “David in Cambridge” :-)

There was a comment from Eric about reading an unlimited amount of data, which is obviously something I should fix, and I will do that when I get time. Thanks for the advice.

Liz Upton avatar

Hi David – very happy to keep you as “David in Cambridge”! (There are an awful lot of Davids in Cambridge. It’s a splendid way to anonymise yourself; be thankful your name’s not Fredegonde or something.)

AndrewS avatar

Or “Eben”? ;-)

(disclaimer: I’ve not done any surveys to determine the relative popularities of different names in Cambridge!)

Liz Upton avatar

I prefer Fredegonde. (There was an Edwardian legal historian here in Cambridge who called his two daughters Ermegard and Fredegonde; I’ve always looked on that as a particularly brutal piece of child-rearing.)

AndrewS avatar

Wow.

A friend-of-a-friend was gutted when his wife wouldn’t let him call their daughter Galvatron :)

Liz Upton avatar

I used to work with someone who called his kids Luke and Leia.

Leo White avatar

You might want to have a quick look at the usage of ‘realloc’ as well. In a low memory situation that could return a NULL pointer, which the code doesn’t check for and would attempt to write to.

In the default Raspbian configuration running out of memory should just trigger the OOM-Killer, however it is possible to configure Linux to not do that and return NULL from malloc/realloc.

David avatar

Yes, you’re absolutely right. I will put that on my list, I could attempt to handle out of memory situations. Thanks.

Suchakra avatar

Looks like smoothie.js has been used! :) I used a similar technique to make a sensor display 4 years back on an ARM board: https://suchakra.files.wordpress.com/2011/07/sensor-data.png

Jim43 avatar

How do I uninstall rCPU

Bob avatar

David’s last name is Hobbs, and he has been very responsive on this code — it works a treat!

David avatar

Oh well, so much for anonymity :-) but thanks for the kind words.

Comments are closed