Shane Duffy

Archive for the ‘monitoring’ Category

After getting a CurrentCost energy monitor a week ago I decided it was time to get some useful data out of it. I have 3 phase power so I wanted a tool which would create graphs for each of the phases along with combined total data. The solution to my problems would have to be custom coded and I also wanted an application which could be used cross platform as I regularly use both Windows and OSX.

My choice was to use Adobe Flex as it can provide some nice looking graphs and I have been meaning to do more work using the Flex in flash player or using Adobe Air technology to create a desktop application.

CurrentCost Application

CurrentCost Application

Im creating an application which I can give back to the community which have been developing applications already for the CurrentCost meter. So I decided to use a very simple architecture for this first demo application which uses a simple client server model.

This week I was working on a new project and for the project I needed to keep an eye on the lenght of a queue which was stored in a MySQL table. I already have the very useful MRTG tool installed on the server so I decided to make use of it to create a simple a quick graphs.

For anyone who doesn’t already know what MRTG is its a very handy tool for graphing data. It is normally used to graph things such are network interface traffic stats and works with an RRD data store in the background storing 5 minute averages. MRTG makes it very easy for users to monitor custom data aswell and has a simple input format. All that is required is to write a script which will output 4 lines of data.

Line 1 -current state of the first variable, normally ‘incoming bytes count’
Line 2 -current state of the second variable, normally ‘outgoing bytes count’
Line 3 -string (in any human readable format), telling the uptime of the target.
Line 4 -string, telling the name of the target.

In order to get started graphing that data that I wanted I created this small script below

echo 0
mysql -h localhost -u USER --password=PASSWORD -e "$1" DATABASE | tail -1
echo 0
echo "Queued Items"

When this script is called it takes 1 argument which is in the form of the count query you want to preform. eg “Select count(*) from table_X”

Then in our MRTG cfg file we need to add an entry to call and display this data.

Target[Blackarrow_queue]: `/graphs/collector_links "Select count(*) from table_X"`
MaxBytes[Blackarrow_queue]: 10000
Options[Blackarrow_queue]: nopercent,growright,nobanner,nolegend,noinfo,gauge,integer,transparent,noi
Title[Blackarrow_queue]: Queue Lenght
YLegend[Blackarrow_queue]: records

For a graph like this you’ll want to use similar options to the ones I used above. nopercent disables percentage display, growright tells the graph to read from left to right instead of the default right to left, gauge tell MRTG that the data points are “current status” measurements rather than ever-increasing counters, noi tells MRTG there is no “input” data to compare against “output” data and a few cosmetic display options. The resulting graph looks something like this:

MRTG Custom Stats

Subscribe to this blog now!

Top Clicks

  • None
April 2017
« Feb