==========
cacti模板的创建使用
==========
1. cacti_thold插件监控网卡流量的方法
因为cacti中默认的单位是byte,这样在显示及设置起来比较麻烦,因些我们需要自定义一个cdef模板以供使用,方法如下:
Management->Graph Management->CDEFs->add-->Byte to Mbits(新建的模板名):
Item Value
Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Custom String: 8
Item #3 Operator: *
Item #4 Custom String: 1024
Item #5 Operator: /
Item #6 Custom String: 1024
Item #7 Operator: /
现在就可以在Threshold Templates添加监控流量的模板了,在
Templates-->Threshold Templates-->Add-->Interface - Traffic [traffic_in]/Traffic [traffic_out]-->Data Manipulation-->Data Type:CEDF-->Threshold CDEF:Byte to Mbits
Alert Emails-->邮件报警,多个邮件地址以逗号分隔
2. cacti监控硬盘使用率并报警
cacti本身的模板只可以监控硬盘的使用大小,而不能监控使用百分率,所以我们要自定义cdef来监控硬盘使用率,并借助thold插件实现报警功能.
cacti目录下,vi include/global_arrays.php修改如下:
- $custom_data_source_types = array(
- "CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
- "ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
- "ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
- "SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
- "SIMILAR_DATA_SOURCES_DUPS" => "All Similar Data Sources (Include Duplicates)",
- "CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
- "CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
- "CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
- "CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit",
- "VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source", 此为增加的一行
- "COUNT_ALL_DS_NODUPS" => "Count of All Data Sources (Don't Include Duplicates)",
- "COUNT_ALL_DS_DUPS" => "Count of All Data Sources (Include Duplicates)",
- "COUNT_SIMILAR_DS_NODUPS" => "Count of All Similar Data Sources (Don't Include Duplicates)",
- "COUNT_SIMILAR_DS_DUPS" => "Count of All Similar Data Sources (Include Duplicates)");
cacti管理界面-->Graph Management-->CDEFs->add-->monitor-hdd-percent(新建的模板名):
Item Value
Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Custom String: 100
Item #3 Operator: *
Item #4 Special Data Source: VALUE_OF_HDD_TOTAL
Item #5 Operator: /
现在就可以在Threshold Templates添加监控硬盘的模板了:
Threshold Templates-->Add-->Host MIB - Hard Drive Space [hdd_used](新建模板名)-->Data Manipulation-->Data Type:CEDF-->Threshold CDEF:monitor-hdd-percent(选择刚自定义的模板)
Alert Emails-->邮件报警,多个邮件地址以逗号分隔
3.模板应用
Devices-->选择主机-->Create Graphs for this Host-->Auto-create thresholds自动应用刚创建的所有模板
Created threshold for the Graph 'ucd_load5min' using the Data Source 'ucd_load5min'
Created threshold for the Graph 'Interface - Traffic' using the Data Source 'traffic_in'
Created threshold for the Graph 'Interface - Traffic' using the Data Source 'traffic_out'
Created threshold for the Graph 'Host MIB - Hard Drive Space' using the Data Source 'hdd_used'
Created threshold for the Graph 'Host MIB - Hard Drive Space' using the Data Source 'hdd_used'
Created threshold for the Graph 'Host MIB - Hard Drive Space' using the Data Source 'hdd_used'
==========
cacti问题总结
==========
1. 被监控服务器如果做了安全限制需开放iptables和hosts.allow的snmpd端口和协议
echo 'snmpd:192.168.7.x' >>/etc/hosts.allow
iptables -I INPUT -p udp --dport 161 -s 192.168.7.250 -m state --state NEW -j ACCEPT 只开放udp协议161端口即可
2.cacti访问页面空白及安装过程出错信息排查
1)ldd /usr/bin/rrdtool 查看加载模块是否有not found
如果有提示找不到的文件libfreetype
执行命令LD_DEBUG=libs /usr/bin/rrdtool 可以查找当rrdtool文件运行时所查找的路径,提示是到/lib /usr/lib下去寻找,
而该路径下没有些文件,locate libfreetype.so.6查看下命令在哪里做个软链接过去就行了
2)#snmpwalk -v 2c -c public 192.168.7.250 if 手动获取snmp信息是否成功
手动执行/usr/bin/php poller.php
php cmd.php 查看出错信息
把web管理界面上的debug打开,再查看cacti.log和apache访问日志进行排查,Setting-->General-->Poller Logging Level-->DEBUG - Statistics....
安装gcc,gcc-c++ 因为rrdtool是用gcc编译的
3. 另root和cactiuser里crontab有重复的php执行poller.php文件,删除root的crontab定时任务,用cactiuser用户去执行
# php poller.php 手动执行出错信息
01/24/2013 08:50:25 AM - POLLER: Poller[0] NOTE: Poller Int: '300', Cron Int: '300', Time Since Last: '24', Max Runtime '298', Poller Runs: '1'
01/24/2013 08:50:25 AM - POLLER: Poller[0] NOTE: Cron is configured to run too often! The Poller Interval is '300' seconds, with a minimum Cron period of '300' seconds, but only 24 seconds have passed since the poller last ran.
提示poller设置每隔300s运行一次,但现在只24s就运行了一次,太频繁了。
把crontab里的php poller每5分钟执行一次改为每分钟执行一次再改回来,问题不明
最好是以cactiuser帐号来运行OK
sudo -u cactiuser /usr/bin/php -f /var/www/html/cacti/poller.php
#php cmd.php 手动执行查看出错信息
4. cacti部分图片显示不了 cacti目录路径/var/www/html/cacti/include/config.php下
$url_path = "/cacti/"; 或include/global.php下指定cacti路径
5. 创建模板不成功查看出错日志:CMDPHP: Poller[0] ERROR: SQL Assoc Failed!, Error:'1064', SQL:"SELECT * FROM thold_template ORDER BY name ASC LIMIT 0,"
谷歌了N久答案:Just goto Console->Settings->Thresholds and press the save button OK
转载于:https://blog.51cto.com/iceeggplant/1129825