Server Sensors


In an effort to keep an eye on my new server build, I installed lm-sensors and hddtemp to let me monitor the temperatures.

sudo apt-get install lm-sensors hddtemp

After that, make hddtemp excutable without root privilages using

sudo chmod u+s /usr/sbin/hddtemp

And attempt to find your computers sensors with

sudo sensors-detect

Personally, I just select yes for everything, but do so at your own risk.

After that I set up a script which greps and cuts its way to being readable

#! /bin/bash
echo -n "CPU       >>    "
sensors | grep Temp1 | cut -c 15-21
echo -n "Fan       >>    "
sensors | grep Fan2 | cut -c 13-20
echo -n "M/B       >>    "
sensors | grep Temp2 | cut -c 15-21
echo -n "HD        >>    "
hddtemp /dev/sdb | cut -c 24-28
echo -n "Device                Total  Used Free      Mount"
df -h | grep /home

This also displays the space used on my /home drive, and the output looks like this;

CPU       >>    36.0°C
Fan       >>    3060 RPM
M/B       >>    37.0°C
HD        >>    33°C
Device                    Total  Used Free      Mount
/dev/sdb1             459G   53G  407G  12% /home

EDIT: It was rather inconvenient to SSH into the server everytime I wanted to check the sensors, so using the root cron, and a simple script, I rigged it to run the sensors script every five minutes, and to copy that to the web directory on my server. That lets me just check the script report through my web browser, much more convenient.

This is the script executed by the root crontab every five minutes;

#! /bin/bash
bash /home/dave/ > /home/dave/.sensors.txt
sleep 100
cp /home/dave/.sensors.txt /var/www/sensors.txt

And here’s the entry called by the root crontab. The root privileges are needed to get the size of the Apt and Squid caches;

#Run sensors script
*/5 * * * *     root /home/dave/

In the meantime, I also modified the script a bit, for more features, and to look better on a web browser. You may or may not prefer it 🙂

#! /bin/bash
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ">>  Run as root to manually clear trash  <<"
echo ">>  Run as root to generate an instantaneous report  <<"
echo -n "CPU          >>    "
sensors | grep Temp1 | cut -c 15-18,20-21
echo -n "FAN          >>    "
sensors | grep Fan2 | cut -c 13-20
echo -n "M/B          >>    "
sensors | grep Temp2 | cut -c 15-18,20-21
echo -n "HD           >>    "
/usr/sbin/hddtemp /dev/sdb | cut -c 24-25,27-28
echo -n "Apt-Cache    >>    "
du -hs /home/dave/.apt-cacher-ng/ | cut -c 1-5
echo -n "Squid Cache  >>    "
du -hs /home/squid/ | cut -c 1-5
echo -n "Device                Total  Used Free      Mount"
df -h | grep /home
free -m
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

After all that, it ends up looking like this in a web browser, and updates itself every five minutes.


2 Responses to “Server Sensors”

  1. 1 ortuno2k

    I’ve got to check it out. I’ve also been thinking about keeping an eye on my server’s health, and your article points me in the right direction.


    • 2 evidex

      No worries 🙂 Almost all hardware these days will support this =]

%d bloggers like this: