==========
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