You are here
CACTI Tuning – Script to Monitor Cacti Polling Time data networks and data Programming Tools 

CACTI Tuning – Script to Monitor Cacti Polling Time

One of the most critical points when tuning Cacti is to consider the duration of the polling cycle.

It’s important to reduce the amount of time the polling cycle takes for a number of reasons

  1. Short polling cycle times result in more avialability of the processor on the system to perform other tasks, such as serving graphs and web pages to the clients
  2. Consistently short polling times indicate a lean and trim polling cycle with no thread-hogging or idling.
  3. Staying clear of the 300second hard cutoff and avoiding stepping on the next poll.

In order to accomplish this goal, you can certainly look at the log files, either through the cli or through the web gui utility, but it’s also good to to look at a graphical representation to

  • examine trends / relationship between data sources numbers and duration of polls
  • come to a rough-estimate on how many RRDs or datasources you will theoretically be limited to (given the max 300 seconds)
  • perform forensics on exceptions to standard deviations, ie. spikes
  • better understand the effect your Apache and Mysql processing has on poll cycles at different times

This is an article in my series of Cacti Tuning.  Please see another great point about tuning the max OIDs per request.

 

Realworldnumbers CACTI Tuning - Script to Monitor Cacti Polling Time - Output Graph
Realworldnumbers CACTI Tuning – Script to Monitor Cacti Polling Time – Sample Graph

 

The above graph is a representation of the same data you can extract either through the GUI or the CLI.

Realworldnumbers CACTI Tuning - Script to Monitor Cacti Polling Time - Log File Filtered to show polling time
Realworldnumbers CACTI Tuning – Script to Monitor Cacti Polling Time – Gui used for Log File Filtered to show polling time

 

CLI method:

[root@cactiserver ~]# grep -i "System stats\: TiMe" /var/log/cacti/cacti.log | head -10
08/14/2012 09:55:48 AM - SYSTEM STATS: Time:46.6067 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:28370 RRDsProcessed:12712
08/14/2012 10:00:48 AM - SYSTEM STATS: Time:46.3102 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:28370 RRDsProcessed:12776
08/14/2012 10:05:49 AM - SYSTEM STATS: Time:48.2241 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:28370 RRDsProcessed:12776
08/14/2012 10:10:50 AM - SYSTEM STATS: Time:48.7651 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:28370 RRDsProcessed:12776
08/14/2012 10:15:49 AM - SYSTEM STATS: Time:48.5671 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:28370 RRDsProcessed:12776
08/14/2012 10:21:09 AM - SYSTEM STATS: Time:67.3014 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:60264 RRDsProcessed:20833
08/14/2012 10:26:12 AM - SYSTEM STATS: Time:71.2526 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:60264 RRDsProcessed:20833
08/14/2012 10:31:10 AM - SYSTEM STATS: Time:68.5250 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:60264 RRDsProcessed:20833
08/14/2012 10:36:11 AM - SYSTEM STATS: Time:69.1648 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:60264 RRDsProcessed:20833
08/14/2012 10:41:14 AM - SYSTEM STATS: Time:73.5677 Method:spine Processes:12 Threads:8 Hosts:223 HostsPerProcess:19 DataSources:60264 RRDsProcessed:20833

Making the script

Create The Scripts Needed on the CLI

You’ll need some kind of “stats” user.  Create one if you don’t already have it, or just use root and substitute accordingly.

Make the temporary directory we’re going to need.

[root@cactiserver ~]# mkdir  /home/stats/CACTI

[root@cactiserver ~]# cat > /usr/share/cacti/scripts/time.pl
#!/usr/bin/perl

#chomp $hostname;

$workingdir=”/home/stats/CACTI/”;
open( FILE, “< $workingdir/poller.log”) or die “Cant do it\n”;
my @lines = <FILE>;
close(FILE);
foreach (@lines){

chomp $_;
@array=split(/\./,$_);
print $array[0];
};

 

Make sure your script has the permissions and ownership needed to run it from the apache web user.  In the case of Redhat, this is user called “apache”.  In the case of Ubuntu type distros, the username will be “www-data”.

[root@cactiserver ~]# ls -la /usr/share/cacti/scripts/time.pl
-rwxr-xr-x 1 apache apache 245 May 15 2012 /usr/share/cacti/scripts/time.pl

 

Create a cronjob as such.  We’ll need it to ensure that we only get the last few lines of the cacti log file.  Otherwise we run the risk of chewing through tens of thousands of lines just to get the bottom.  Nonsense!

 

[root@cactiserver ~]# crontab -l

### CACTI Poller Time Retreival
3,8,13,18,23,28,33,38,43,48,53,58 * * * * grep “SYSTEM STATS: Time:” /var/log/cacti/cacti.log | tail -1 | awk ‘ { print $7 } ‘ > /stats/CACTI/poller.log

[root@cactiserver  ~]# ls -la /home/stats/CACTI/poller.log
-rw-r–r– 1 stats stats 13 Nov 19 02:28 /home/stats/CACTI/poller.log

 

Create Data Input Method

Realworldnumbers CACTI Tuning - Script to Monitor Cacti Polling Time - Data input methods
Realworldnumbers CACTI Tuning – Script to Monitor Cacti Polling Time – Data input methods

Create Data Template

Realworldnumbers CACTI Tuning - Script to Monitor Cacti Polling Time - Data Template
Realworldnumbers CACTI Tuning – Script to Monitor Cacti Polling Time – Data Template

Create Data Template

Realworldnumbers CACTI Tuning - Script to Monitor Cacti Polling Time -Graph Template
Realworldnumbers CACTI Tuning – Script to Monitor Cacti Polling Time -Graph Template

 

Get that graph going

Add the graph to your “localhost” device.  Select “Cacti Polling Time” under the Associated Graph Templates. Create the graph and let her fly!

 

Appendix – Here’s the XML to import

 

If you get confused about what the hashes actually mean, check out my article on cacti hashes.

<cacti>	
	<hash_000024203d207f15a6f92d23299e5baac09be2>
		<name>Cacti Polling Time</name>
		<graph>
			<t_title></t_title>
			<title>Cacti Polling Time</title>
			<t_image_format_id></t_image_format_id>
			<image_format_id>1</image_format_id>
			<t_height></t_height>
			<height>120</height>
			<t_width></t_width>
			<width>600</width>
			<t_slope_mode></t_slope_mode>
			<slope_mode>on</slope_mode>
			<t_auto_scale></t_auto_scale>
			<auto_scale>on</auto_scale>
			<t_auto_scale_opts></t_auto_scale_opts>
			<auto_scale_opts>2</auto_scale_opts>
			<t_auto_scale_log></t_auto_scale_log>
			<auto_scale_log></auto_scale_log>
			<t_scale_log_units></t_scale_log_units>
			<scale_log_units></scale_log_units>
			<t_auto_scale_rigid></t_auto_scale_rigid>
			<auto_scale_rigid></auto_scale_rigid>
			<t_auto_padding></t_auto_padding>
			<auto_padding>on</auto_padding>
			<t_export></t_export>
			<export>on</export>
			<t_upper_limit></t_upper_limit>
			<upper_limit>0</upper_limit>
			<t_lower_limit></t_lower_limit>
			<lower_limit>0</lower_limit>
			<t_base_value></t_base_value>
			<base_value>1000</base_value>
			<t_unit_value></t_unit_value>
			<unit_value></unit_value>
			<t_unit_exponent_value></t_unit_exponent_value>
			<unit_exponent_value></unit_exponent_value>
			<t_vertical_label></t_vertical_label>
			<vertical_label>Secs</vertical_label>
		</graph>
		<items>
			<hash_100024994c3fa74ab618cf29e040ea2561e68b>
				<task_item_id>hash_0800248070d968170d1f33677e0f2c97e322a9</task_item_id>
				<color_id>5800FF</color_id>
				<alpha>FF</alpha>
				<graph_type_id>7</graph_type_id>
				<consolidation_function_id>1</consolidation_function_id>
				<cdef_id>0</cdef_id>
				<value></value>
				<gprint_id>hash_060024e9c43831e54eca8069317a2ce8c6f751</gprint_id>
				<text_format>Polling Time</text_format>
				<hard_return></hard_return>
				<sequence>1</sequence>
			</hash_100024994c3fa74ab618cf29e040ea2561e68b>
			<hash_100024f2701e884ed90140e242b8aed6fc27a5>
				<task_item_id>hash_0800248070d968170d1f33677e0f2c97e322a9</task_item_id>
				<color_id>0</color_id>
				<alpha>FF</alpha>
				<graph_type_id>9</graph_type_id>
				<consolidation_function_id>4</consolidation_function_id>
				<cdef_id>0</cdef_id>
				<value></value>
				<gprint_id>hash_060024e9c43831e54eca8069317a2ce8c6f751</gprint_id>
				<text_format>Current:</text_format>
				<hard_return></hard_return>
				<sequence>2</sequence>
			</hash_100024f2701e884ed90140e242b8aed6fc27a5>
			<hash_100024f057819158695f0fe0db89d2f75715ac>
				<task_item_id>hash_0800248070d968170d1f33677e0f2c97e322a9</task_item_id>
				<color_id>0</color_id>
				<alpha>FF</alpha>
				<graph_type_id>9</graph_type_id>
				<consolidation_function_id>1</consolidation_function_id>
				<cdef_id>0</cdef_id>
				<value></value>
				<gprint_id>hash_060024e9c43831e54eca8069317a2ce8c6f751</gprint_id>
				<text_format>Average:</text_format>
				<hard_return></hard_return>
				<sequence>3</sequence>
			</hash_100024f057819158695f0fe0db89d2f75715ac>
			<hash_1000249823b2dc6eea8ce6987273949003c7c0>
				<task_item_id>hash_0800248070d968170d1f33677e0f2c97e322a9</task_item_id>
				<color_id>0</color_id>
				<alpha>FF</alpha>
				<graph_type_id>9</graph_type_id>
				<consolidation_function_id>3</consolidation_function_id>
				<cdef_id>0</cdef_id>
				<value></value>
				<gprint_id>hash_060024e9c43831e54eca8069317a2ce8c6f751</gprint_id>
				<text_format>Maximum:</text_format>
				<hard_return>on</hard_return>
				<sequence>4</sequence>
			</hash_1000249823b2dc6eea8ce6987273949003c7c0>
		</items>
		<inputs>
			<hash_09002431be463402ac8f88ded96a2943bbf09c>
				<name>Data Source [Time]</name>
				<description></description>
				<column_name>task_item_id</column_name>
				<items>hash_000024994c3fa74ab618cf29e040ea2561e68b|hash_000024f2701e884ed90140e242b8aed6fc27a5|hash_000024f057819158695f0fe0db89d2f75715ac|hash_0000249823b2dc6eea8ce6987273949003c7c0</items>
			</hash_09002431be463402ac8f88ded96a2943bbf09c>
		</inputs>
	</hash_000024203d207f15a6f92d23299e5baac09be2>
	<hash_010024ecbde94e2124889dbf89bf539de83025>
		<name>Cacti Polling Time</name>
		<ds>
			<t_name></t_name>
			<name>CACTI Polling Interval</name>
			<data_input_id>hash_030024c06827171adad46f693111cf914611f1</data_input_id>
			<t_rra_id></t_rra_id>
			<t_rrd_step></t_rrd_step>
			<rrd_step>300</rrd_step>
			<t_active></t_active>
			<active>on</active>
			<rra_items>hash_150024c21df5178e5c955013591239eb0afd46|hash_1500240d9c0af8b8acdc7807943937b3208e29|hash_1500246fc2d038fb42950138b0ce3e9874cc60|hash_150024e36f3adb9f152adfa5dc50fd2b23337e</rra_items>
		</ds>
		<items>
			<hash_0800248070d968170d1f33677e0f2c97e322a9>
				<t_data_source_name></t_data_source_name>
				<data_source_name>Time</data_source_name>
				<t_rrd_minimum></t_rrd_minimum>
				<rrd_minimum>U</rrd_minimum>
				<t_rrd_maximum></t_rrd_maximum>
				<rrd_maximum>U</rrd_maximum>
				<t_data_source_type_id></t_data_source_type_id>
				<data_source_type_id>1</data_source_type_id>
				<t_rrd_heartbeat></t_rrd_heartbeat>
				<rrd_heartbeat>600</rrd_heartbeat>
				<t_data_input_field_id></t_data_input_field_id>
				<data_input_field_id>hash_0700242d290ffe7b211f843585de2d88e2ec48</data_input_field_id>
			</hash_0800248070d968170d1f33677e0f2c97e322a9>
		</items>
		<data>
		</data>
	</hash_010024ecbde94e2124889dbf89bf539de83025>
	<hash_030024c06827171adad46f693111cf914611f1>
		<name>CACTI Polling Interval</name>
		<type_id>1</type_id>
		<input_string>&lt;path_cacti&gt;/scripts/time.pl</input_string>
		<fields>
			<hash_0700242d290ffe7b211f843585de2d88e2ec48>
				<name>Time</name>
				<update_rra>on</update_rra>
				<regexp_match></regexp_match>
				<allow_nulls></allow_nulls>
				<type_code></type_code>
				<input_output>out</input_output>
				<data_name>Time</data_name>
			</hash_0700242d290ffe7b211f843585de2d88e2ec48>
		</fields>
	</hash_030024c06827171adad46f693111cf914611f1>
	<hash_150024c21df5178e5c955013591239eb0afd46>
		<name>Daily (5 Minute Average)</name>
		<x_files_factor>0.5</x_files_factor>
		<steps>1</steps>
		<rows>600</rows>
		<timespan>86400</timespan>
		<cf_items>1|3</cf_items>
	</hash_150024c21df5178e5c955013591239eb0afd46>
	<hash_1500240d9c0af8b8acdc7807943937b3208e29>
		<name>Weekly (30 Minute Average)</name>
		<x_files_factor>0.5</x_files_factor>
		<steps>6</steps>
		<rows>700</rows>
		<timespan>604800</timespan>
		<cf_items>1|3</cf_items>
	</hash_1500240d9c0af8b8acdc7807943937b3208e29>
	<hash_1500246fc2d038fb42950138b0ce3e9874cc60>
		<name>Monthly (2 Hour Average)</name>
		<x_files_factor>0.5</x_files_factor>
		<steps>24</steps>
		<rows>775</rows>
		<timespan>2678400</timespan>
		<cf_items>1|3</cf_items>
	</hash_1500246fc2d038fb42950138b0ce3e9874cc60>
	<hash_150024e36f3adb9f152adfa5dc50fd2b23337e>
		<name>Yearly (1 Day Average)</name>
		<x_files_factor>0.5</x_files_factor>
		<steps>288</steps>
		<rows>797</rows>
		<timespan>33053184</timespan>
		<cf_items>1|3</cf_items>
	</hash_150024e36f3adb9f152adfa5dc50fd2b23337e>
	<hash_060024e9c43831e54eca8069317a2ce8c6f751>
		<name>Normal</name>
		<gprint_text>%8.2lf %s</gprint_text>
	</hash_060024e9c43831e54eca8069317a2ce8c6f751>
</cacti>

 

Related posts

One thought on “CACTI Tuning – Script to Monitor Cacti Polling Time

  1. […] I would also recommend keeping an eye on the polling cycle time with this handy little graph. […]

Leave a Comment