Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== CACTI Monitoring of xAP ====== [[http://www.cacti.net/|cacti]] is a great monitoring tool wouldn't it be cool if ANY xAP data value could be monitored? With a xAP caching Lua applet running as a [[hah_plugboard_v2|plugboard]] script on the [[HAH]] and one small python script for CACTI to use this indeed is possible. {{:livebox:cacti-graph.png}} ===== Setting up the xAP data cache ===== The first step is to set-up and configure Lua script ''xapCacheWebserverApplet.lua'' which will cache an xAP data value and provide a URL for later accessing. The script is supplied as a sample in the ''/etc_ro_fs/plugboard/samples'' directory on the [[HAH]], it's also available as a [[http://www.homeautomationhub.com/content/webserver-written-lua-serve-xap-data-values-applet|post on the forum]] Here is how to we modify the VFS configuration to capture data we are interested in. <code lua> local vfs = { filter={ xap.Filter{["xap-header"] = { source="dbzoo.livebox.Controller:1wire.*", class="xAPBSC.event" } }, xap.Filter{["xap-header"] = { source="dbzoo.nanode.>", class="xAPBSC.event" } }, xap.Filter{["xap-header"] = { source="dbzoo.livebox.jeenode:>", class="xAPBSC.event" } }, }, data={} } </code> Read more about the [[hah_plugboard_v2#filter]] class and pattern matching. After restarting the [[hah_plugboard_v2|plugboad]] engine we can point our web browser at <code>http://<HAH-IP>:8080/</code> and see the xAP frames being cached. Once some xAP messages have been cached you should see a web page like this: <code> Cached xap-header source keys dbzoo.livebox.jeenode:outside.lobat dbzoo.nanode.jeenode:3.temp dbzoo.nanode.jeenode:4.temp dbzoo.nanode.jeenode:3.lobat dbzoo.livebox.jeenode:outside.temp2 dbzoo.nanode.jeenode:7.temp dbzoo.nanode.jeenode:4.lobat dbzoo.livebox.Controller:1wire.1 dbzoo.livebox.jeenode:store.light dbzoo.nanode.jeenode:2.light dbzoo.livebox.jeenode:outside.light dbzoo.nanode.jeenode:3.light dbzoo.livebox.jeenode:store.temp dbzoo.nanode.jeenode:4.light dbzoo.nanode.jeenode:2.temp dbzoo.nanode.jeenode:7.humi dbzoo.nanode.jeenode:7.lobat dbzoo.nanode.jeenode:2.lobat </code> ===== Configuring CACTI ===== The installation of [[http://www.cacti.net|CACTI]] is beyond the scope of this document and I'll assume you already have it setup and running, there are many guides our there to show you how to install this product. I will however show how I did it. ==== Installing Cacti on CentOS6 ==== For CentOS6.x installing is a snap If you don't already have the EPEL repository installed into /etc/yum.repos.d/ then do this first. <code> rpm -Uvh http://fedora.mirror.uber.com.au/epel/6/i386/epel-release-6-8.noarch.rpm </code> Check how to install for older release and Fedora @ http://fedoraproject.org/wiki/EPEL Then install cacti <code> yum install cacti </code> ===== Customizing for xAP ===== You need to include one custom script that will called by the cacti data poller to reach our to our LUA caching web applet to grab xAP data values. On my system this script appear on a linux server at: ''/var/lib/cacti/scripts/xapquery.py'' don't forget to set the permission bits <code> [root@wombat scripts]# ls -l xapquery.py -rwxr-xr-x 1 root root 588 Jun 20 16:14 xapquery.py [root@wombat scripts]# </code> You'll need to make one modification to this code and update the HARDCODED IP address to point to you HAH system. <code python> #!/usr/bin/python # # QUERY the xapCache # # Usage: # ./xapquery.py dbzoo.arduino.temp input.state text import sys import time import urllib2 def getValue(target,section,key): f = urllib2.urlopen("http://livebox.local:8080/%s/%s/%s" % (target,section,key)) ret = f.read() if key == "state": if ret == "on": return 1 elif ret: return ret return 0 if len(sys.argv) < 3: out="value:0" else: out="value:%s" % getValue(sys.argv[1], sys.argv[2], sys.argv[3]) # Useful for debugging #f = open("/var/log/cacti/xapquery.log","a") #f.write("%s: %s %s\n" % (time.ctime(), sys.argv, out)) #f.close() print out </code> We can verify that the script it working correctly and that the LUA xAP caching applet it working by running a simple test. I'm assuming here that you have a 1wire temperature sensor connected. Adjust this test for a suitable endpoint if you don't.\\ The arguments are ''<TARGET> <SECTION> <KEY>'' <code> [root@wombat scripts]# ./xapquery.py dbzoo.livebox.Controller:1wire.1 input.state text value:18.3 [root@wombat scripts]# </code> ==== Create external xAP data template ==== First we need to register this external script by **adding a new Collection Method** {{cacti-s1.png?800}} Once we have select the ADD hyperlink complete the following form, this sets up the external script and configures 1 output value and 3 input values. {{cacti-s2.png}} Now we need to create a DATA Template - you can see we will add a xAPQuery item here. {{cacti-s3.png?800}} Give the data template a name - I've called my simply xAPQuery and attached the "DATA INPUT METHOD" we created earlier. {{cacti-s4.png}} ==== Creating a data source ==== Now the template is in PLACE we can create a DATA SOURCE, this is the thing that collects data about some xAP endpoint we define. You can see I've already created some early and they appear as listed items in the table below. {{cacti-s5.png?800}} For each xAP data value you want to collect data on repeat this process. You will perform this action for each ''Filter'' you created in the xAP LUA data cache. To create the data source to we use the xAPQuery template we defined earlier. {{cacti-s6.png}} Want we are going to collect is the outside temperature reading from the 1wire device. Complete the form and press CREATE. Here we supply the xAP TARGET, SECTION and KEY. {{cacti-s7.png}} One the create button has been pressed we can provide addition data to the xAPQuery script that collect this data. ==== Creating a GRAPH ==== Now the exciting bit we create graph to plot the information gathered. You can delete and create new graph without affecting the data that is being collected, so feel free to experience in this section on your own. The image below shows the graphs that I have registered. Use the ADD hyperlink to create a new graph {{cacti-s9.png?800}} We don't have any predefined graph template or host we need to attached this data to. {{cacti-s10.png}} Give your graph a TITLE {{cacti-s11.png}} Now press ADD so that we can attach the DATA SOURCES to this graph {{cacti-s12.png}} Now we attach the DATA SOURCE we created early as a graph data item. {{cacti-s13.png}} ==== Putting it on the Graph Console Tab ==== {{:livebox:cacti-s14.jpg|}} {{:livebox:cacti-s15.jpg|}} {{:livebox:cacti-s16.jpg|}} {{:livebox:cacti-s17.jpg|}} {{:livebox:cacti-s18.jpg|}} That's all there is to it! ===== Polling faster ===== I like to poll every minute instead of the default 5 mins. {{:livebox:cacti-s20.jpg|}} Then make an adjustment to your cron file to fire the poller every minute. <code> # cat /etc/cron.d/cacti 0-59 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1 # </code> livebox/xap_cacti.txt Last modified: 2013/05/31 11:57by garrydwilms