Cacti Graphing Watchport USB Temperature Sensor

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
Cwadd
Posts: 9
Joined: Wed Apr 06, 2011 11:02 pm

Cacti Graphing Watchport USB Temperature Sensor

Post by Cwadd »

Hello all,

I've got a perfectly working instance of Cacti, and some new Digi Watchport/H USB Temperature / Humidity Sensors. The sensors communicate via terminal ASCII commands, however I've scripted it in such a way I have log files updating every minute. I'm very flexible on the configuration of the log files (CSV etc).

I'm trying to find a way to graph the temperature and humidity using Cacti. After plenty of research, it seemed like the only way to do this would be to output results from the sensor into a log file, and then parse that log file and graph it with rrdtool / Cacti.

Can anyone help point me in the right direction? I seem to have hit a wall here. As noted, I've got a log file updating with date / time stamp, temperature and humidity, but I can't figure out how to graph it. I've been looking into generating an OID with the log file results, and I've come across an application called fetchlog, but I've only been able to find instructions for integrating that with Nagios, and not Cacti.

I was frankly hoping there would be a way to parse the file directly with Cacti but I'm not seeing that option either.

This is a new world to me, however I'm very interested in getting these going, as I have quite a few of them and many applications (from server cabinets to reptiles to home automation to you name it). Any help at this point would be greatly appreciated :)
madsn
Cacti User
Posts: 50
Joined: Tue Oct 13, 2009 6:26 am

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by madsn »

I'm really not an expert on cacti, but I have had to do something similar to what you trying to. I wanted to graph the number of rrd files on my system. I did this in the following way.

1. I created a normal bash script:

Code: Select all

#!/bin/bash
cd /var/www/cacti/rra/
ls -l | wc -l
Output from the script

Code: Select all

[root@mysrv scripts] . number_of_rrd.sh
709
The script is placed in the /var/www/cacti/scripts folder. Remember to set the chmod to 755

2. Create a Data Input Method
In the console menu in cacti I chose the Data Input Method and added a new one with the following information:
Name: Unix - Number of RRD Files
Input Type: Script/Command
Input String: <path_cacti>/scripts/number_of_rrd.sh

Pressed save and then afterwards I was given the opportunity to select the name of the Output fields (an internal name that is used in cacti for the output value of my script). This value I called no_of_rrds

3. Create a Data Template
Again cacti console menu Data Template add:
Data Template
Name: Unix - Number of RRD files
Data Source
Name: |host_description| - RRD files
Data Input Method: Unix - Number of RRD files (The data Input method I created earlier)
Associated RRA's: Here everything is marked except Hourly
Step: 300
Data Source Active: check
Data Source Item
Internal Data Source Name: no_of_rrds (The name I chose for the output value of my script)
Min Value: 0
Max Value:10000
Heartbeat: 600
Outputfield: no_of_rrds (This field might first become visible after pressing save)

3. Create a Graph template
Cacti console Graph Template add:
Add a graph Item
Data Source: Unix Number of RRD files
Color:4444FF
Opacity:100%
Graph Item Type: AREA
Consolidation function: AVERAGE
CDEF function: None
GPRINT Type: Normal

Pressed save and the item is added. (More items can be added such as the current value, max value etc. play around with this when the grpahing is working)

Template
Name Unix - RRDs
Grpah Template
Title: |host_description| RRDs
Image Format: png
Height: 120
Width: 500
Slope Mode: check
Auto Scale: check
Autos cale option: scond radio button

After this Save

4. Create a Graph
This I think is not necessary to explain :-)

Hopefully everything works :-)
madsn
Cacti User
Posts: 50
Joined: Tue Oct 13, 2009 6:26 am

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by madsn »

Cwadd
Posts: 9
Joined: Wed Apr 06, 2011 11:02 pm

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by Cwadd »

Wow, your post and that link look great! Thanks so much!

I'm going to peek over the link and see what I can't come up with. Your method looks easier, but I'll check both just in case :)
Cwadd
Posts: 9
Joined: Wed Apr 06, 2011 11:02 pm

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by Cwadd »

Well that seemed easy! I've got graphs that appear to work!

I'm going to leave my cabinet door open for a little while to see if I can visibly watch the temperature drop a bit, but it seems to be okay!

Only one weird thing I'm looking for a bit more assistance on. I've created the scripts for Cacti to call, and the way I designed it, it will output the raw data when the script is run (which is working) and then I had another line set up to actually log the results (by appending date and time to the actual sensor results), which worked fine when run manually, but does not appear to be running with Cacti.

Is there any way to further troubleshoot with this? Outside of my log not populating, and the graph polling data, I'm not sure what to do. Cacti log is clear as is /var/log/messages.
Cwadd
Posts: 9
Joined: Wed Apr 06, 2011 11:02 pm

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by Cwadd »

Scratch that, I figured it out! Once I get it polished up a bit, I'll post what I've done so others can benefit hopefully :)
madsn wrote: 3. Create a Graph template
Cacti console Graph Template add:
Add a graph Item
Data Source: Unix Number of RRD files
Color:4444FF
Opacity:100%
Graph Item Type: AREA
Consolidation function: AVERAGE

CDEF function: None
GPRINT Type: Normal
I am just curious about your values here. I as well am no expert :) however I noticed something a little funky with my graphs. My "Current" temperature may show 22 in the graph, but if I run the script, I see 21. It seems to take a few minutes to kick into 21, while the sensor value reads 21 the whole time. I am wondering about the AREA AVERAGE function, thinking perhaps the graph is pulling an average of the values returned from the sensor instead of the actual current value? Or perhaps the sensor is just too accurate that Cacti's rounding it up (the sensor goes to 4 decimal points)?

Otherwise so far so good :) I've got almost 24 hours worth of data from 6 different sensors which is great.
madsn
Cacti User
Posts: 50
Joined: Tue Oct 13, 2009 6:26 am

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by madsn »

Hi Cwadd

Well glad you managed to get the graphs working! Regarding the two values:

Graph Item Type: AREA

This just means that the graph is filled with the color you chose, instead of being only a line.

Consolidation function: AVERAGE

Yes you are correct this is some kind of averaging function. How it works I don't know, but instead of AVERAGE you can chose LAST, this will give you the last value retrieved from your script.
Cwadd
Posts: 9
Joined: Wed Apr 06, 2011 11:02 pm

Re: Cacti Graphing Watchport USB Temperature Sensor

Post by Cwadd »

Looks like I just had some silly permission errors. I forgot to attempt to run the script as apache user, and since I was testing the script as root, my log / temp files were all modded to root read write, with only read for everyone else. I couldn't figure out if rebuilding the poller cache was working, or if it was me running the scripts manually as root. It would appear that when I ran the script manually as root, it updated the temporary file (that apache did not have access to write to, but could read), and therefore updated the value on my graph as at next poll, it would pull the updated values from the temp file due to the fact I ran it as root. After that though, it would just flat line at that value until I cleared the cache and manually polled.

So now that I've double checked everything, and actually troubleshooted the script as the apache user, it seems like everything is working as expected. I've got accurate graphs now (I've been verifying on the side with a food grade IR temperature sensor), they're logging for redundancy, and I've even set up thresholds that alert me if they're met. Here's a little snip of two of my temperature graphs:

Image

I'm still working on polishing the script (for example, warning the user if permissions are not correct hehe), but once is all said and done, anyone interested can reference
http://waddz.net/index.php/watchport

Thanks again for all your assistance madsn! Wouldn't have gotten this far without you :)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests