Cacti is a great tool. I use it for collecting and graphing all kinds of data about my servers and networks. But after using it for so many years, I’ve learned its weaknesses. It is quite easy to make a mistake setting up Cacti that you later come to regret – and cannot fix. Before using Cacti to graph real data, you need to understand how it works.
This is the first in a series of related blog posts about Cacti.
Underneath the pretty pretty wrapper, Cacti uses rrdtool to store and graph data. If you really want to understand rrdtool itself, read the tutorial and man pages. In a nutshell, rrdtool stores data in round-robin archives, and can output that data in graphical form.
Cacti uses rrdtool for three things. It:
- Creates data sources by using “
rrdtool create” to create a new RRD file.
- Stores collected data by using the “
rrdtool update” command to add new data rows to round-robin archives in RRD files.
- Graphs collected data by using the “
rrdtool graph” command to generate a PNG file and display it to the user.
You can see these steps in Cacti. Under “Management” -> “Graph Management”, select a graph. Then click on “Turn on graph debug mode” to see the exact rrdtool command line Cacti will use to output a graph to the user.
RRDTool Command: /usr/bin/rrdtool graph - \ --imgformat=PNG \ --start=-86400 \ --end=-60 \ --title='venkman - CPU Usage' \ --rigid \ --base=1000 \ --height=120 \ --width=750 \ --alt-autoscale-max \ --lower-limit='0' \ --units-exponent='0' \ --vertical-label='percent' \ --slope-mode \ --font TITLE:10: \ --font AXIS:8: \ --font LEGEND:8: \ --font UNIT:8: \ DEF:a="/var/www/cacti/rra/venkman_cpu_system_1110.rrd":'cpu_system':AVERAGE \ DEF:b="/var/www/cacti/rra/venkman_cpu_user_1111.rrd":'cpu_user':AVERAGE \ DEF:c="/var/www/cacti/rra/venkman_cpu_nice_1109.rrd":'cpu_nice':AVERAGE \ CDEF:cdefbf='TIME,1370037928,GT,a,a,UN,0,a,IF,IF,TIME,1370037928,GT,b,b,UN,0,b,IF,IF,TIME,1370037928,GT,c,c,UN,0,c,IF,IF,+,+' \ AREA:a#FF0000FF:"System" \ GPRINT:a:LAST:"Current\:%8.2lf" \ GPRINT:a:AVERAGE:"Average\:%8.2lf" \ GPRINT:a:MIN:"Minimum\:%8.2lf" \ GPRINT:a:MAX:"Maximum\:%8.2lf\n" \ AREA:b#0000FFFF:"User":STACK \ GPRINT:b:LAST:" Current\:%8.2lf" \ GPRINT:b:AVERAGE:"Average\:%8.2lf" \ GPRINT:b:MIN:"Minimum\:%8.2lf" \ GPRINT:b:MAX:"Maximum\:%8.2lf\n" \ AREA:c#00FF00FF:"Nice":STACK \ GPRINT:c:LAST:" Current\:%8.2lf" \ GPRINT:c:AVERAGE:"Average\:%8.2lf" \ GPRINT:c:MIN:"Minimum\:%8.2lf" \ GPRINT:c:MAX:"Maximum\:%8.2lf\n" \ LINE1:cdefbf#000000FF:"Total" \ GPRINT:cdefbf:LAST:" Current\:%8.2lf" \ GPRINT:cdefbf:AVERAGE:"Average\:%8.2lf" \ GPRINT:cdefbf:MIN:"Minimum\:%8.2lf" \ GPRINT:cdefbf:MAX:"Maximum\:%8.2lf\n" RRDTool Says: OK
Likewise, you can “Turn on data source debug mode” to see the command Cacti uses to update data sources. To see how a data source is created, set Cacti logging to “debug” before creating it. The output will appear in the Cacti log.
The first thing to do when debugging a “Why isn’t my graph appearing”* problem is to try the above steps. If an error message wasn’t printed with the debug output, try to paste the command line into the terminal as the Cacti user. This is usually Apache’s user, such as “www-data” on Debian.
* Safety tip for new users: be patient. It takes at least two polling cycles (2 or 10 minutes, depending on your setup) before most graphs appear in Cacti.
On Debian or Ubuntu systems, Cacti stores RRD files in /var/lib/cacti/rrd/. You can run manual rrdtool commands here to examine the RRD structure (
rrdtool info), to dump the raw data (
rrdtool dump) or graph it (
Thanks for the simple explanation on cacti. I have run cacti successfully but seem to have messed up my rrd config. A few graphs i created in the beginning are working well showing correct historical information. However 90% of my other graphs are showing only 2days on historical graph data and frankly this is driving me nuts. I have tried what I can to fix it but to no avail and our sales team need it to bill our customers correctly.
My organization is ready to pay for consultancy to fix this, would you kindly help?
Comments feed for this article
Trackback link: https://www.tolaris.com/2013/05/31/cacti-and-rrdtool/trackback/