上周給同事講解了cacti的安裝及其使用時做了一份ppt,在這里將這份ppt簡單梳理一下介紹一下cacti在我們日常工作中的監控使用
cacti的結構
在廣義上來說cacti是一套網絡流量監測圖形分析工具,但從狹義來說cacti只是由php語言實現的一個軟件,
它需要PHP,apache,Mysql,SNMP,RRDTool等工具的支持

從上圖可以很明確看出cacti的三層架構之間的關系
第一層是數據采集,通過snmp簡單網絡協議,和一批自定義的腳本進行采集
第二層是數據存儲,分別通過mysql存儲cacti的模板和一些一定的信息,RRDTool用來存儲所監控到的性能文件,后綴為.rrd
第三層是數據展現,cacti的web方式展現
cacti主要功能是用snmp服務獲取數據,然后用rrdtool儲存和更新數據,當用戶需要查看數據的時候,rrdtool生成圖表呈現給用戶。因此, snmp和rrdtool是cacti的關鍵,snmp關系著數據的收集,rrdtool關系著數據存儲和圖表的生成.

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

使用SNMP進行網絡管理需要下面幾個重要部分:管理基站,管理代理,管理信息庫和網絡管理工具。管理基站通常是一個獨立的設備,它用作網絡管理者進行網 絡管理的用戶接口。基站上必須裝備有管理軟件,管理員可以使用的用戶接口和從MIB取得信息的數據庫,同時為了進行網絡管理它應該具備將管理命令發出基站的能力
注:關于MIB介紹可以看<
SNMP MIB完整手冊>
*.net-snmp
NET-SNMP是一個代理SNMP協議的軟件,并提供管理端的查詢工具,支持多種擴展方式
在被監測和監測機器進行安裝
http://www.net-snmp.org/download.html
配置
/etc/snmp/snmpd.conf
設置自啟動
/usr/sbin/snmpd -c /usr/local/net-snmp/snmpd.conf &
測試
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 (負載檢查)
*.RRDTool
RRDTool使用RRD(Round Robin Database)作為存儲格式,Round robin是一種處理定量數據、以及當前元素指針的技術。RRDTool主要用來跟蹤對象的變化情況,生成這些變化的走勢圖
RRDTool的存儲特點
存儲數據的數據庫空間看成一個圓
指針會隨著數據的讀寫操作在圓的刻度上自動移動
圓沒有起點和終點
當所有的空間都存滿了數據,就又從頭開始存放
RRDtool 所使用的數據庫文件的后綴名是'.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定時器
接下來就可以訪問
*.進入cacti的設置
配置SNMP版本,rrdtool類別,和net-snmp的工具路徑
具體的安裝配置和應用就不演示,下面是ppt附件,安裝和配置有什么問題可以同我聯系
--------------------------------
補充
有朋友對rrdtools提了一點問題:
RRDTool保存數據是循環的,而且大小不變。那是不是說,他只能保存一定數量活一段數據,然后保持更新。
比如:RRD只有6個刻度,用來保存一個小時內,每10分鐘的流量。從10點10分開始的話,到11點就滿了,那么就開始循環刷新了。
11點10分的數據就覆蓋了10點10分的數據。
可是如果我分析的沒錯的話,那數據不就丟失了么?如果想查看歷史怎么辦呢?
因為rrd整個存儲空間的大小就是一個固定的值,在一段時間后,當所有空間都存滿數據后,就會從頭開始存放,所以這涉及到rrdtool的前期規劃,以下是截取了http://www.rrdtool.org的說明
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