上周給同事講解了cacti的安裝及其使用時(shí)做了一份ppt,在這里將這份ppt簡(jiǎn)單梳理一下介紹一下cacti在我們?nèi)粘9ぷ髦械谋O(jiān)控使用
cacti的結(jié)構(gòu)
在廣義上來(lái)說(shuō)cacti是一套網(wǎng)絡(luò)流量監(jiān)測(cè)圖形分析工具,但從狹義來(lái)說(shuō)cacti只是由php語(yǔ)言實(shí)現(xiàn)的一個(gè)軟件,
它需要PHP,apache,Mysql,SNMP,RRDTool等工具的支持

從上圖可以很明確看出cacti的三層架構(gòu)之間的關(guān)系
第一層是數(shù)據(jù)采集,通過snmp簡(jiǎn)單網(wǎng)絡(luò)協(xié)議,和一批自定義的腳本進(jìn)行采集
第二層是數(shù)據(jù)存儲(chǔ),分別通過mysql存儲(chǔ)cacti的模板和一些一定的信息,RRDTool用來(lái)存儲(chǔ)所監(jiān)控到的性能文件,后綴為.rrd
第三層是數(shù)據(jù)展現(xiàn),cacti的web方式展現(xiàn)
cacti主要功能是用snmp服務(wù)獲取數(shù)據(jù),然后用rrdtool儲(chǔ)存和更新數(shù)據(jù),當(dāng)用戶需要查看數(shù)據(jù)的時(shí)候,rrdtool生成圖表呈現(xiàn)給用戶。因此, snmp和rrdtool是cacti的關(guān)鍵,snmp關(guān)系著數(shù)據(jù)的收集,rrdtool關(guān)系著數(shù)據(jù)存儲(chǔ)和圖表的生成.

snmp抓到數(shù)據(jù)不是存儲(chǔ)在mysql中而是存在rrdtool生成的rrd文件中,rrdtool對(duì)數(shù)據(jù)的更新和存儲(chǔ)就是對(duì)rrd文件的處理,rrd 文件是大小固定的檔案文件,它能夠存儲(chǔ)的數(shù)據(jù)筆數(shù)在創(chuàng)建時(shí)已經(jīng)定義.
Mysql配合PHP程序存儲(chǔ)一些變量數(shù)據(jù)并對(duì)變量數(shù)據(jù)進(jìn)行調(diào)用,如:主機(jī)名、主機(jī) ip,snmp 團(tuán)體名、端口號(hào)、模板信息等變量。
*.SNMP協(xié)議
SNMP(簡(jiǎn)單網(wǎng)絡(luò)管理協(xié)議)前身是簡(jiǎn)單網(wǎng)關(guān)監(jiān)控協(xié)議(SGMP), 用來(lái)對(duì)通信線路進(jìn)行管理
↓
加入符合Internet定義的
SMI和MIB進(jìn)行體系整合
↓
簡(jiǎn)單網(wǎng)絡(luò)管理協(xié)議(SNMP)是Internet組織用來(lái)管理Internet的網(wǎng)絡(luò)協(xié)議
*.MIB & SMI
MIB, 管理信息庫(kù),由網(wǎng)絡(luò)管理協(xié)議訪問的管理對(duì)象數(shù)據(jù)庫(kù),它包括SNMP可以通過網(wǎng)絡(luò)設(shè)備的SNMP管理代理進(jìn)行設(shè)置的變量
SMI,管理信息結(jié)構(gòu),用于定義通過網(wǎng)絡(luò)管理協(xié)議可訪問的對(duì)象的規(guī)則。SMI定義在MIB中使用的數(shù)據(jù)類型及網(wǎng)絡(luò)資源在MIB中的名稱或表示。
*.SNMP的網(wǎng)絡(luò)模型

使用SNMP進(jìn)行網(wǎng)絡(luò)管理需要下面幾個(gè)重要部分:管理基站,管理代理,管理信息庫(kù)和網(wǎng)絡(luò)管理工具。管理基站通常是一個(gè)獨(dú)立的設(shè)備,它用作網(wǎng)絡(luò)管理者進(jìn)行網(wǎng) 絡(luò)管理的用戶接口。基站上必須裝備有管理軟件,管理員可以使用的用戶接口和從MIB取得信息的數(shù)據(jù)庫(kù),同時(shí)為了進(jìn)行網(wǎng)絡(luò)管理它應(yīng)該具備將管理命令發(fā)出基站的能力
注:關(guān)于MIB介紹可以看<
SNMP MIB完整手冊(cè)>
*.net-snmp
NET-SNMP是一個(gè)代理SNMP協(xié)議的軟件,并提供管理端的查詢工具,支持多種擴(kuò)展方式
在被監(jiān)測(cè)和監(jiān)測(cè)機(jī)器進(jìn)行安裝
http://www.net-snmp.org/download.html
配置
/etc/snmp/snmpd.conf
設(shè)置自啟動(dòng)
/usr/sbin/snmpd -c /usr/local/net-snmp/snmpd.conf &
測(cè)試
snmpwalk -v 2c -c public 127.0.0.1
snmpwalk -v 1 -c public 127.0.0.1 .1.3.6.1.4.1.2021.10 (負(fù)載檢查)
*.RRDTool
RRDTool使用RRD(Round Robin Database)作為存儲(chǔ)格式,Round robin是一種處理定量數(shù)據(jù)、以及當(dāng)前元素指針的技術(shù)。RRDTool主要用來(lái)跟蹤對(duì)象的變化情況,生成這些變化的走勢(shì)圖
RRDTool的存儲(chǔ)特點(diǎn)
存儲(chǔ)數(shù)據(jù)的數(shù)據(jù)庫(kù)空間看成一個(gè)圓
指針會(huì)隨著數(shù)據(jù)的讀寫操作在圓的刻度上自動(dòng)移動(dòng)
圓沒有起點(diǎn)和終點(diǎn)
當(dāng)所有的空間都存滿了數(shù)據(jù),就又從頭開始存放
RRDtool 所使用的數(shù)據(jù)庫(kù)文件的后綴名是'.rrd'
*.Cacti的安裝
需要安裝以下軟件
1)安裝Apache,Mysql,PHP
2)安裝RRDTool
(cgilib-0.5.tar.gz,zlib-1.2.3.tar.gz,libpng-1.2.18.tar.gz,freetype-2.3.5.tar.gz,libart_lgpl-2.3.17.tar.gz,rrdtool-1.2.23.tar.gz)
3)安裝net-snmp
4)安裝cacti
*.Cacti的配置
修改cacti的config.php
新增crontab定時(shí)器
接下來(lái)就可以訪問
*.進(jìn)入cacti的設(shè)置
配置SNMP版本,rrdtool類別,和net-snmp的工具路徑
具體的安裝配置和應(yīng)用就不演示,下面是ppt附件,安裝和配置有什么問題可以同我聯(lián)系
--------------------------------
補(bǔ)充
有朋友對(duì)rrdtools提了一點(diǎn)問題:
RRDTool保存數(shù)據(jù)是循環(huán)的,而且大小不變。那是不是說(shuō),他只能保存一定數(shù)量活一段數(shù)據(jù),然后保持更新。
比如:RRD只有6個(gè)刻度,用來(lái)保存一個(gè)小時(shí)內(nèi),每10分鐘的流量。從10點(diǎn)10分開始的話,到11點(diǎn)就滿了,那么就開始循環(huán)刷新了。
11點(diǎn)10分的數(shù)據(jù)就覆蓋了10點(diǎn)10分的數(shù)據(jù)。
可是如果我分析的沒錯(cuò)的話,那數(shù)據(jù)不就丟失了么?如果想查看歷史怎么辦呢?
因?yàn)閞rd整個(gè)存儲(chǔ)空間的大小就是一個(gè)固定的值,在一段時(shí)間后,當(dāng)所有空間都存滿數(shù)據(jù)后,就會(huì)從頭開始存放,所以這涉及到rrdtool的前期規(guī)劃,以下是截取了http://www.rrdtool.org的說(shuō)明
When monitoring the state of a system, it is convenient to have the data available at a constant time interval. Unfortunately, you may not always be able to fetch data at exactly the time you want to. Therefore RRDtool lets you update the log file at any time you want. It will automatically interpolate the value of the data-source (DS) at the latest official time-slot (interval) and write this interpolated value to the log. The original value you have supplied is stored as well and is also taken into account when interpolating the next log entry.
Consolidation
You may log data at a 1 minute interval, but you might also be interested to know the development of the data over the last year. You could do this by simply storing the data in 1 minute intervals for the whole year. While this would take considerable disk space it would also take a lot of time to analyze the data when you wanted to create a graph covering the whole year. RRDtool offers a solution to this problem through its data consolidation feature. When setting up an Round Robin Database (RRD), you can define at which interval this consolidation should occur, and what consolidation function (CF) (average, minimum, maximum, total, last) should be used to build the consolidated values (see rrdcreate). You can define any number of different consolidation setups within one RRD. They will all be maintained on the fly when new data is loaded into the RRD.
Round Robin Archives
Data values of the same consolidation setup are stored into Round Robin Archives (RRA). This is a very efficient manner to store data for a certain amount of time, while using a known and constant amount of storage space.
It works like this: If you want to store 1'000 values in 5 minute interval, RRDtool will allocate space for 1'000 data values and a header area. In the header it will store a pointer telling which slots (value) in the storage area was last written to. New values are written to the Round Robin Archive in, you guessed it, a round robin manner. This automatically limits the history to the last 1'000 values (in our example). Because you can define several RRAs within a single RRD, you can setup another one, for storing 750 data values at a 2 hour interval, for example, and thus keep a log for the last two months at a lower resolution.
The use of RRAs guarantees that the RRD does not grow over time and that old data is automatically eliminated. By using the consolidation feature, you can still keep data for a very long time, while gradually reducing the resolution of the data along the time axis.
Using different consolidation functions (CF) allows you to store exactly the type of information that actually interests you: the maximum one minute traffic on the LAN, the minimum temperature of your wine cellar, the total minutes of down time, etc.
----------------------------------------
by 陳于喆
QQ:34174409
Mail: dongbule@163.com