Update 2012-07-25: These instructions have been (mostly) superseded by a new version of this guide. Follow that document instead.
I recently acquired a TEMPer USB thermometer. It’s a cheap, convenient way to measure temperature in your server closet or machine room. My home “server closet” consists of the living room entertainment center, which is an enclosed wooden structure. It gets pretty hot, so I decided to track the ambient temperature with Cacti.
I assume you’ve already set up Cacti on Ubuntu 10.04 LTS, but any recent Debian-based system will work. This guide will help you install the necessary Perl modules to work with the TEMPer, and configure the data source and graph in Cacti. In the end, you will have pretty graphs like so:
Overview:
- Install prerequisite perl modules
- Install temper-mon
- Create udev rule for TEMPer device
- Create Cacti templates
- Create Cacti graph
1. Install prerequisite perl modules
The script that communicates with the TEMPer requires the Perl module Device::USB. For that, you need to first install some packages from the repository, then use cpan to install the rest:
apt-get install libusb-dev libinline-perl libdevice-usb-pcsensor-hidtemper-perl
Or use CPAN:
cpan -fi Device::USB
cpan -fi Device::USB::PCSensor::HidTEMPer
If you haven’t used cpan
in the past, first configure it by running cpan
, and answering “yes” to the question “Would you like me to configure as much as possible automatically?” Once that’s complete you’ll be able to run the lines above. Configuring cpan
is an entire problem on its own, but the automated setup should work.
2. Install temper-mon
temper-mon is my own perl code for working with the TEMPer. It is based on various sources I’ve found online, and has inline documentation for those that wish to modify it. It assumes you have only one TEMPer device connected to a USB port, and prints the temperature reading to standard out. If you have multiple devices you can edit the source to support that, but that also requires changes to the Cacti script setup later on.
Download temper-mon and install it in /usr/local/bin (or somewhere the web server can execute).
cd /usr/local/bin
sudo wget http://www.tolaris.com/blog/wp-content/uploads/2011/05/temper-mon.gz
sudo gzip -d temper-mon.gz
sudo chmod 755 temper-mon
At this point you can run temper-mon
as root. But let’s make it work for the webserver user first.
3. Create udev rule for TEMPer device
Now we must create a udev rule for the TEMPer. This will tell udev to make the device world-writable, which means any user on the system can send data to the device. This is necessary because the device doesn’t return a temperature reading without first sending it some data. This isn’t a security hole unless you don’t want attackers knowing the temperature of your closet.
Using your favourite editor, create the file /etc/udev/rules.d/99-temperusb.rules, containing:
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1130", ATTRS{idProduct}=="660c", MODE="666"
Or do it directly with:
echo 'SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1130", ATTRS{idProduct}=="660c", MODE="666"' | sudo tee /etc/udev/rules.d/99-temperusb.rules
Now disconnect and reconnect the TEMPer. You should now have a USB device with “rw-rw-rw-” permissions. Its exact location in the USB tree may vary. Mine is:
# ls -la /dev/bus/usb/002/002 crw-rw-rw- 1 root root 189, 129 2011-04-19 19:59 /dev/bus/usb/002/002
You can verify you have the correct device with lsusb
:
# lsusb Bus 003 Device 002: ID 1130:660c Tenx Technology, Inc.
Make sure your device has ID 1130:660c, or temper-mon
won’t work for you. However, you can use these instructions with any other command-line agent which prints data to standard out with the Cacti instructions later on.
Now we test temper-mon. Make sure it works as the webserver user, www-data:
$ sudo su - www-data $ /usr/local/bin/temper-mon 35
If you get a reading, you’re ready to move on to the next step.
4. Create Cacti templates
It is possible to skip this step and just create graphs without templates. However, I prefer to maintain proper templates for all data sources and graphs. This scales better. I plan to add more sensors later so I can measure ambient room temperature, and outdoor temperature.
You may want to see this how-to for graphing data from a script in Cacti.
The steps in Cacti follow. In all causes where I have not specified a value, use the default.
- Create the Data Input Method
- “Collection Methods” -> “Data Input Methods” -> “Add”
- Name: TEMPer USB deg C
- Input Type: Script/Command
- Input String: /usr/local/bin/temper-mon
- Press “Create”
- “Output Fields” -> “Add”
- Field [Output]: temp_celsius
- Friendly Name: Temperature in degrees Celsius
- Create the Data Template
- “Templates” -> “Data Templates” -> “Add”
- Data Template Name: Local Temperature
- Date Source / Name: |host_description| – Temperature
- Data Source / Data Input Method: TEMPer USB deg C
- Data Source Item / Internal Data Source Name: temp_c
- Press “Create”
- “Output Field” will now say “temp_celsius – Temperature in degrees Celsius”. Press “Save”.
- Create the Graph Template
- “Templates” -> “Graph Templates” -> “Add”
- Template Name: Local Temperature
- Title: |host_description| – Temperature
- Lower Limit: 20 (optional, I find this gives useful graph heights)
- Unit Exponent Value: 0
- Vertical Label: degrees Celsius
- Press “Create”
- Now create the line on the graph.
- “Graph Template Items” -> “Add”
- Data Source: Local Temperature – (temp_c)
- Color: 0000FF
- Graph Item Type: LINE1
- GPRINT Type: Exact Numbers (you may prefer Load Average, if available)
- Text Format: Temperature
- Press “Create”
- Finally, create the four items in the graph legend.
- “Graph Template Items” -> “Add”
- Data Source: Local Temperature – (temp_c)
- Graph Item Type: GPRINT
- Consolidation Function: LAST
- GPRINT Type: Exact Numbers
- Text Format: “Current:”
- Press “Create”
- Repeat this last step 3 more times, replacing the Consolidation Function and Text Format with AVERAGE, MIN, and MAX. On the last item, check Insert a Hard Return
- Your Graph Template should now look like:
- Press “Save”
5. Create a Cacti graph
We are finally ready to create a graph.
- “Management” -> “Devices” -> Select your Cacti server
- Click “Create Graphs for this Host”
- “Graph Templates” -> “Create:” -> select “Local Temperature” from pull-down
- Press “Create”
That’s it! You now have a temperature graph. I recommend using the threshold plugin to issue a warning alert if your server area gets too hot.
The Cacti script/command method has one limitation: the TEMPer must be connected to your Cacti server. But what if you want to connect it to another server, or perhaps use multiple devices around your machine room to gather data? The solution is to create an SNMP agent for the TEMPer. I’ll revisit that in a later post.
-
Hi there,
Using a clean 10.10 server install do you need to modify any of the available repositories?.
doing apt-get install libdevice-usb-perl it says it cant be found. I can manually find the .deb packages and install but then this causes problems with installing cacti.
Manually installing the deb I can get a reading though from the USB thermometer which is good.
Many Thanks
-
Hi Tyler,
Thanks for the update. I found on a clean install of 10.10 server I had to do a cpan -i Inline and a cpan -i Inline::C before I could do cpan -fi Device::USB. Just a heads up for other users that use these instructions.
Thanks again.
Gavin
-
Just got some my Temper, but lsusb shows:
Bus 003 Device 008: ID 0c45:7401 Microdia
Looks like they changed the ID. have anyone experienced this?
-
-
31 comments
Comments feed for this article
Trackback link: https://www.tolaris.com/2011/05/12/graphing-data-from-a-temper-usb-probe-in-cacti/trackback/