Jazz Up lm-sensors with Graphics and Notifications

7505

When last we met, we learned about lm-sensors, the excellent tool for monitoring CPU temperature, fan speeds, and motherboard voltages. Now we’re going to learn about changing the labels in sensors output to make it more useful, look at some good graphical front ends, and see how to configure and send notifications.

Customizing Labels

The default labels for your various sensors are sometimes not very helpful, as this snippet of sensors output shows.

fan1:  900 RPM
fan2: 1020 RPM

Fortunately, we can change the labels to anything we want. Let us relabel fan1 and fan2 more descriptively in the lm-sensors configuration file. (See Advanced lm-sensors Tips and Tricks on Linux for information on lm-sensor’s configuration file.)

chip "nct6776-*"
  label fan1 "CPU fan"
  label fan2 "Case fan"

Now in the sensors output it’s clear what they are.

CPU fan:   900 RPM
Case fan: 1020 RPM

Psensor

Psensor is my favorite lm-sensors graphical front-end. It supports multiple system monitors, including lm-sensors, hddtemp, smartmontools, and XNVCtrl for monitoring NVidia GPU temperatures. I love its nice user-friendly interface because all configurations are right there and you don’t have to hunt for them (Figure 1).

Psensor graphical front-end for lm-sensors.

There are checkboxes on the right of the main window to control which sensors appear in the graph. Click on any sensor to configure it; options include hiding it, graph color, setting alarm thresholds, enabling desktop notifications, and changing its name. Change colors, monitoring intervals, enable logging, and set which monitors Psensor listens to in the Psensor > Preferences menu (Figure 2).

Preferences menu

Desktop alerts are good, and Psensor supports scripts to execute any kind of notifications or actions you want. Enter your script name on the Psensor > Preferences > Sensors tab, in the “Script executed when alarm is raised” field. This example script sends an email and shuts down the computer when CPU temperatures are too high.

#!/bin/bash
echo "I am shutting down right now!" | 
/usr/bin/mail -s "[LinuxServer] I'm melting, help" 
carla@bratgrrl.com && shutdown -h now

This simple script plays a sad trombone:

#!/bin/bash
play /home/carla/sounds/sad_trombone.wav

These scripts use good old-fashioned Unix commands to do the work. /usr/bin/mail is provided by the s-nail package on my Ubuntu 16.04 system. Other distributions use mailx, which installs the traditional BSD mail client.

mail can send messages directly, without needing an SMTP server. Maybe it’s just me, but I kept having problems and couldn’t get it to send messages, so I installed ssmtp, the simple SMTP server. If you’re already running an MTA like Postfix or Exim, you don’t need ssmtp. ssmtp is not a mail transfer agent (MTA) like Postfix and Exim. It is a simple relay agent that sends messages to an upstream mail server. You must configure /etc/ssmtp/ssmtp.conf to accept messages in the same way that you configure your mail client, with the server name and port, TLS/SSL type, and your authorization if your upstream server requires it. This example is typical of hosted mail servers, which usually rely on STARTTLS.

mailhub=mail.example.com:25
AuthUser=carla@example.com
AuthPass=password
UseSTARTTLS=YES

It also has options for configuring the locations of SSL certificates if necessary. Whatever your regular mail client needs is what ssmtp needs. If you get the “sendmail: Cannot open mail.example.com:25” error when you send a message then your port number or TLS/SSL configuration is wrong. See man 5 ssmtp.conf for complete options.

You also need to add all local system users that will send notifications to /etc/ssmtp/revaliases:

root:carla@example.com:mail.example.com:25
carla:carla@example.com:mail.example.com:25

Another cool notification option is to send yourself SMS text messages. There are a couple of ways to do this on Linux. One is to use a commercial SMS gateway, which is easy and costs a little money. Another way is to use a USB GSM modem plugged into your computer, with a prepaid SIM card. This is a fun topic for another day, and if you have done this, please give some details in the comments.

More Graphical Interfaces

Graphical front ends to lm-sensors come and go. Conky and xsensors are two reliable oldtimers. Conky is endlessly configurable and supports everything under the sun. xsensors is barebones. Both run without complaints on all Linux distributions.

Temperature sensor plugin
I like having a set of temperature sensors in my taskbar. These are specific to the graphical desktop environment you are running. Thermal Monitor for KDE is pretty nice. I use xfce4-sensors-plugin on my Xfce4 desktop (Figure 3).

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.