2018年4月21日 星期六

RRDTools 的基本概念與在 Windows 下使用 RRDTools

下載 Windows 使用的 RRDTools 工具

  • 請打開置個網頁 RRD for Windows ,下載取得 rrdtool-1.2.15-cygwin-1.5.20.zip 檔案
  • 這個壓縮檔案內有下圖的檔案
    RRDTools for Windows

建立 RRD 資料庫

現在,讓我們來產生一個 RRD 資料庫,在這裡,我們使用了 rrdtool create 這個命令,下達底下指令,用來產生 RRD 資料庫。我們建立一個資料來源 Data Source,其名字為 speed 且該資料來源的類型是 COUNTER,接著,設定兩個 RRA,第一個是會儲存 24 筆,每五分鐘的紀錄,也就是會記錄下 24 x 5 = 144 分鐘 的紀錄,另外一個是會儲存 10筆,每 6 x 5 = 30 分鐘的紀錄,因此,在這裡將可以看到 30 x 10 = 300 分鐘 = 5 小時的紀錄
Console
rrdtool create test.rrd --start 920804400 DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:6:10

更新 RRD 資料庫的資料

現在,我們使用 rrdtool update 指令,來進行 RRD 資料庫的更新作業,詳細指令,可以參考底下指令,再進行資料更新的時候,我們需要取得現在時間之 Unix 的秒數。
Console
rrdtool update test.rrd 920804700:12345 920805000:12357 920805300:12363
rrdtool update test.rrd 920805600:12363 920805900:12363 920806200:12373
rrdtool update test.rrd 920806500:12383 920806800:12393 920807100:12399
rrdtool update test.rrd 920807400:12405 920807700:12411 920808000:12415
rrdtool update test.rrd 920808300:12420 920808600:12422 920808900:12423

查詢 RRD 資料庫內的資料

我們可以使用 rrdtool fetch 指令取得 RRD 資料庫內的資料
Console
rrdtool fetch test.rrd AVERAGE --start 920804400 --end 920809200
這是輸出結果內容
 920804700: nan
 920805000: 4.0000000000e-02
 920805300: 2.0000000000e-02
 920805600: 0.0000000000e+00
 920805900: 0.0000000000e+00
 920806200: 1.4316516463e+07
 920806500: 4.0000000000e-02
 920806800: 1.3333333333e-02
 920807100: 3.6666666667e-02
 920807400: 6.6666666667e-03
 920807700: 1.6666666667e-02
 920808000: 1.2333333333e-01
 920808300: 1.0000000000e-02
 920808600: 1.6666666667e-02
 920808900: 4.6666666667e-02
 920809200: nan
 920809500: nan

產生圖片

要產生 RRD 資料庫內的資料,可以使用底下指令來產生出來
Console
rrdtool graph speed.png --start 920804400 --end 920808000 DEF:myspeed=test.rrd:speed:AVERAGE LINE2:myspeed#FF0000 --font DEFAULT:9:D:\Vulcan\Projects\2\Roman.ttf
這是 RRDTool 產生出來的圖片
RRDTool

沒有留言:

張貼留言