Category Archives: Cacti

Cacti Spine

Add in crontab these 2 scrypts to rebuild poller cache and reindex hosts in databse

27 3 * * * www /usr/local/bin/php -q /usr/local/www/html/cacti/cli/rebuild_poller_cache.php > /dev/null 2>&1
52 3 * * * www /usr/local/bin/php -q /usr/local/www/html/cacti/cli/poller_reindex_hosts.php -id=All > /dev/null 2>&1

Минимални настройки на php.ini – Колкото повече, толкова повече!

max_execution_time = 180 ; Maximum execution time of each script, in seconds
max_input_time = 180 ; Maximum amount of time each script may spend parsing request data;
max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 512M ; Maximum amount of memory a script may consume
short_open_tag = On
upload_max_filesize = 24M
post_max_size = 24M

Минимална конфигурация на my.cnf – за препоръчване да се ползва тази от статс-а, защото е преправена (направена)

[mysqld]
# MOST IMPORTANT FOR SPINE/BOOST PERFORMANCE
tmp_table_size = 512M
max_heap_table_size = 512M

# SOME TUNING
key_buffer = 256M
max_allowed_packet = 16M
myisam_sort_buffer_size = 32M
net_buffer_length = 8K
query_cache_size = 128M
read_buffer_size = 1M
read_rnd_buffer_size = 32M
skip-external-locking
sort_buffer_size = 128M
table_open_cache = 1024
table_definition_cache = 1024

# ENABLE LOGGING SLOW QUERIES
log_slow_queries
long_query_time = 2
log_queries_not_using_indexes = 1

# DISABLE BIN LOG
#log-bin=mysql-bin
#binlog_format=mixed

Слага се boost plugin за cacti. Прави се папка, в която да кешира rra-тата

Mysql tuning – cacti

Enable Slow Query Log

1. Enter the MySQL shell and run the following command:

set global slow_query_log = ‘ON’;

2. Enable any other desired options. Here are some common examples:

Log details for queries expected to retrieve all rows instead of using an index:

set global log_queries_not_using_indexes = ‘ON’

Set the path to the slow query log on my.cnf:

log_slow_queries = 1
slow_query_log_file = /var/log/mysql/slow-query.log

Set the amount of time a query needs to run before being logged:

set global long_query_time = ’20’;

(default is 10 seconds)
3. Confirm the changes are active by entering the MySQL shell and running the following command:

show variables like ‘%slow%’;

Create INDEXes for cacti

CREATE INDEX `data_template_data_id` ON `data_input_data` (`data_template_data_id`);
CREATE INDEX `host_id_snmp_query_id_snmp_index` ON data_local (`host_id`,`snmp_query_id`,`snmp_index`);
CREATE INDEX `local_data_id_data_source_name` ON data_template_rrd (`local_data_id`,`data_source_name`);
CREATE INDEX `graph_template_id_local_graph_id` ON graph_templates_item (`graph_template_id`,`local_graph_id`);
CREATE INDEX `local_graph_template_item_id` ON graph_templates_item (`local_graph_template_item_id`);
CREATE INDEX `host_id_snmp_query_id_snmp_index` ON host_snmp_cache (`host_id`,`snmp_query_id`,`snmp_index`);
CREATE INDEX `local_data_id_rrd_path` ON poller_item (`local_data_id`,`rrd_path`);
CREATE INDEX `host_id_rrd_next_step` ON poller_item (`host_id`,`rrd_next_step`);
create index order_key3 on graph_tree_items (order_key(3));
create index order_key6 on graph_tree_items (order_key(6));
create index order_key9 on graph_tree_items (order_key(9));
CREATE INDEX host_id_snmp_query_id ON host_snmp_cache (host_id,snmp_query_id);
CREATE INDEX host_id_snmp_port ON poller_item (host_id,snmp_port);
CREATE INDEX task_item_id ON graph_templates_item (task_item_id);

Cacti Weathermap – switch went down

The cactihost plugin
One of the new data source plugins in Weathermap 0.9 is cactihost. This takes a cacti “device ID” and uses it to query the cacti database for the current state of the device (simple so far). Cacti devices have 4 states: up, down, recovering and disabled, which have a number too: 0=disabled, 1=down, 2=recovering and 3=up.
The plugin returns the current state for both the ‘in’ and ‘out’ bandwidth values. Obviously, these aren’t much use for links, but for nodes they are handy.
Using the results
You can use the resulting numbers to assign a colour to the label of your nodes. To do this, define a new SCALE, so that each of 0,1,2,3 falls in a different coloured band:
SCALE cactiupdown 0 0.5 192 192 192
SCALE cactiupdown 0.5 1.5 255 0 0
SCALE cactiupdown 1.5 2.5 0 0 255
SCALE cactiupdown 2.5 3.5 0 255 0

This gives grey,red,blue and green for disabled, down, recovering and up, respectively.
Now you can add a TARGET and USESCALE line to your NODE, to make it use this SCALE:
NODE mynode
TARGET cactihost:33
USESCALE cactiupdown
LABEL my node label
ICON images/myniceicon.png
LABELOFFSET S

The result is a NODE where the label changes colour, depending on the status of device #33.
(If you go to the Devices list in Cacti, you can see the device IDs on the end of the URL for the host’s page…)
The same, with icons…
So far so good, but I like icons. I want the icon to change when the host goes down, like Whats Up does.
Well, as longs as you don’t mind making 4 different copies of each of your icons, this is pretty easy.
NODE mynode
TARGET cactihost:33
USESCALE none
LABEL my node
ICON images/myniceicon_{node:this:state}.png
LABELOFFSET S

So we’ve said to use a SCALE called ‘none’ – that stops the label from changing colour. We still collect the data using a TARGET line though.
The ICON line is a bit more complicated. Since version 0.9, in a lot of Weathermap config you can use these ‘special tokens’ to embed data in strings. You can add them to labels, so the label text shows a value, and also to filenames. There’s a standard set of ‘variable names’ in weathermap for these, and plugins can define new ones. The cactihost plugin defines one called ‘state’ which will have one of 4 words in it: ‘disabled’,’up’,’down’,’recovering’. so if you create icons called myniceicon_up.png, myniceicon_down.png, myniceicon_disabled.png and myniceicon_recovering.png, then weathermap will switch between them as the host state changes.
Making use of DEFAULTS
That’s quite a lot to include in each NODE definition. Most of it is the same, too. By making more use of those special tokens, you can make it a lot more concise:
NODE DEFAULT
TARGET cactihost:{node:this:cacti_id}
USESCALE none
ICON images/myniceicon_{node:this:state}.png
LABELOFFSET S
NODE realnode1
SET cacti_id 33
LABEL the label
NODE realnode2
SET cacti_id 36
LABEL next label

This time, the DEFAULT node has all the real work in it, including a special TARGET string that has a special token in it. It uses a variable that we are defining ourselves, called cacti_id. This is defined in each node using the SET command. Now, if we wanted to do something different with all our cacti nodes, we only have to change it in one place. Each node only has the details that are unique to that node.

function.php – Cacti Monitor

За да работи, мониторинга на какти-то, трябва да се едитне в ~/lib/function.php

677 /*$hosts[$host_id][“status_fail_date”] = ‘0000-00-00 00:00:00’;
678 $hosts[$host_id][“status_rec_date”] = ‘0000-00-00 00:00:00’;
679 */