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 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 data_source_path ON data_template_data (data_source_path);

使用spine替代默认的cmd.php来采集数据

spine官网下载页: https://www.cacti.net/downloads/spine/

解压cacti-spine 
tar -xf cacti-spine-0.8.8b.tar.gz
·安装cacti-spine
cd cacti-spine-0.8.8b
./configure
make
make install

配置cacti-spine
vim /etc/spine.conf
DB_Host localhost
DB_Database ccacti
DB_User cuser
DB_Pass passwdtest
DB_Port 3307

启动测试
/usr/local/spine/bin/spine
一般显示如下为OK
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8a starting
SPINE: Time: 0.1190 s, Threads: 5, Hosts:

console --> settings --> paths页面下
配置Spine Poller File Path路径

console --> settings --> poller页面
Poller Type选定spine

定时采集

# cacit 数据采集
*/1 * * * * root /usr/local/php/bin/php /data/soft/apache/htdocs/cacti/poller.php > /dev/null 2>&

配置优化

console --> settings --> paths页面下

  • Maximum Threads per Process 配置CPU2* #每个进程最大线程数
  • Number of PHP Script Servers 配置10 #只接受1-10,每个spine进程运行服务脚本数量
  • Script and Script Server Timeout Value 配置120 #网络不好,可以配置大一点
  • The Maximum SNMP OID's Per SNMP Get Request 配置10 #0-100,0,1就关闭snmpbulkwalk,

重构rra文件的目录结构

为每个device建立单独的rra目录

  1. 在crontab里禁用poller.php
  2. 关掉poller.php进程
  3. console --> settings --> paths页面下 选项卡中勾选 “Structured RRA Path (/host_id/local_data_id.rrd)”.
  4. 执行如下命令 /usr/local/php/bin/php /usr/local/apache/htdocs/cacti/cli/structure_rra_paths.php --proceed,它会将所有的RRD文件按照device重新分配目录,并修改数据库中的RRD路径(这个php用的shell_exec,chown,chgrp函数,必须要从disable_functions中去掉)
  5. 恢复poller.php的crontab

按照上面3个步骤,710台服务器,24000个RRD文件,完成一次poller.php的时间,缩短到50 seconds。实现了最初的目的。

如果再出现瓶颈,可以考虑安装 Boost 插件来进一步提升性能。我会在未来写一篇关于 Boost 插件的安装与应用的文章,感兴趣的朋友可以关注。

你可能感兴趣的:(cacti优化选项)