Cacti的庫表結(jié)構(gòu)-Data
cacti 我們也用了很久了,但是它的表結(jié)構(gòu)一直都沒有去關(guān)心過,得空抽了半個(gè)晚上的時(shí)間,把它的庫表結(jié)構(gòu)大概看了下,某些字段的含義跟大家分享下:
cacti 的數(shù)據(jù)都是存放在rrdtool 中的,數(shù)據(jù)庫存放的其實(shí)只是配置數(shù)據(jù),cacti 的邏輯對象主要分為三種,data (數(shù)據(jù))、graph (圖片)、host (設(shè)備),這在它的表設(shè)計(jì)中也能很容易的看出來。所以,就分三個(gè)大類來討論了
二、 Data
data 主要就是數(shù)據(jù)獲取,獲取數(shù)據(jù),然后存放到 rrd 文件中,這里存放的數(shù)據(jù),主要就是如何獲取數(shù)據(jù)、和如何存放數(shù)據(jù)這兩種。
1 、 data_input 表
數(shù)據(jù)獲取的方式,在 console 中的 data_input_method 里可以看到。
id :數(shù)據(jù)獲取方式的 id
hash :對應(yīng)的磁盤索引
name :數(shù)據(jù)獲取方式的名字
input_string :如果是腳本的話,那就是腳本的位置了
type_id : type 一直沒找到對應(yīng)的表,可能是程序里寫死了,對應(yīng)的是 input_type ,有 6 個(gè)選項(xiàng),分別是: snmp 、 snmp query 、 script/command 、 script query 、 script – script server 、 script query – script server
2 、 data_input_fields 表
這張表是用來存放一些 data_input 方法中所需要的對象,比如 snmp 的 oid ,那就是一個(gè)對象, script 方式取硬盤時(shí)候,取回來值的名字,單位,都屬于它所定義的范疇。表內(nèi)容,主要是這些對象,和 data_input 的對應(yīng)。
id : input_fields 的 id
data_input_id :對應(yīng) data_input 表中的 id
name 、 data_name :名字
input_output :輸入還是輸出
下面幾個(gè)字段我也不清楚了……
3 、 data_input_data 表
存放的是每個(gè) data 對象的 data_input_field 內(nèi)容。
data_input_field_id : data_input_field 中的 id
data_template_data_id : data_template_data 中的 id
4 、 data_local 表
存放數(shù)據(jù)對象,就是在 console 中的 data source 頁面看到的東東。不過這張表只是簡單的定義一個(gè)對象和對應(yīng)關(guān)系,對象的具體屬性在另外的表中。
id : data 的 id
data_template_id :采用了哪個(gè)數(shù)據(jù)模板,在 data_templates 模板中定義
host_id :是哪個(gè)設(shè)備的數(shù)據(jù),在 host 中定義
snmp_query_id :如果是通過 snmp_query 方式獲取的,那對應(yīng)的 snmp_query 的 id ,如果不是,則為 0
snmp_index : snmp_query 方式獲取數(shù)據(jù)時(shí),獲取數(shù)組的前綴。例如,流量獲取中,端口的 index
5 、 data_template 表
數(shù)據(jù)模板,我們在 console 的 data templates 中看到的東東。
id :數(shù)據(jù)模板的 id
hash :索引
name :名字
6 、 data_template_data 表
具體數(shù)據(jù)對象的信息,包含模板??梢哉J(rèn)為,每一個(gè)對象都代表一個(gè) rrd 文件。
id : data 對象的 id
local_data_template_data_id :如果使用了模板,那這個(gè)就是模板的 id ,定義的位置也是這個(gè)表
local_data_id :對應(yīng)的數(shù)據(jù)對象,在 data_local 表中定義
data_template_id : data_template ,數(shù)據(jù)模板,在 data_template 表中定義。
data_input_id :數(shù)據(jù)獲取的方式,在 data_input 表中定義
*name :名字,就是字面的意思
data_source_path : rrd 文件的路徑
active :是否被激活,可以通過 enable/disable 來控制
rrd_step :步長,默認(rèn)是 300s ,就是 5 分鐘,也就是多長時(shí)間存一個(gè)數(shù)據(jù)( rrdcreate 的選項(xiàng))
7 、 data_template_data_rra 表
數(shù)據(jù)對象和 rra 的對應(yīng), rra 也是 rrdtool 中的概念,是一種數(shù)據(jù)歸檔壓縮的機(jī)制。
data_template_data_id :上張表中定義的 id
rra_id :對應(yīng)的 rra 的 id ,在 rra 表中定義
8 、 data_template_rrd 表
基本上也是 rrdtool 的配置選項(xiàng),一個(gè) rrd 文件可以存多列,叫做 ds ,每個(gè)列代表一組數(shù)據(jù)。這張表可以看成是對這個(gè)列的定義。
id : ds 的 id
local_data_template_rrd_id :如果使用了 ds 的模板,則這里定義模板的 id ,模板定義也在這張表中
local_data_id :數(shù)據(jù) id ,在 data_local 表中定義
data_template_id :采用的數(shù)據(jù)模板,在 data_template_data 中定義
其余的都是 rrdtool 在創(chuàng)建 rrd 文件時(shí)候,對這個(gè) ds 的配置選項(xiàng),例如***值,名字等等。
data 部分還是比較復(fù)雜的,如果和 host 連起來看,就更復(fù)雜了。拋開模板不談,一般來講是有以下的對應(yīng)關(guān)系:
1 、每個(gè) host_id ,都有一組 local_data_id ,例如,一個(gè) cisco 交換機(jī)的 cpu 就是一個(gè) local_data_id ,它的一個(gè)端口—— te1/1 流量,也是一個(gè) local_data_id 。一個(gè) host_id 對應(yīng)多個(gè) local_data_id 。
2 、每個(gè) local_data_id ,就是一個(gè)數(shù)據(jù)源,它必須有一個(gè) rrd 文件與他對應(yīng),所以每個(gè) local_data_id 在 data_template_data 中,必定對應(yīng)一行記錄,必定有一個(gè) rrd 文件。別看 data_template_data 中有那么多記錄,其中 local_data_id 為 0 的,或者 rrd 路徑為空的,那都是模板。
3 、每個(gè) rrd 文件,必然至少有一個(gè) ds ,也就是在 data_template_rrd 中,至少有一條記錄,例如流量,還是 cisco 的交換機(jī),每個(gè)端口代表一個(gè) local_data_id ,有一個(gè) rrd 文件,有兩個(gè) ds ,流入和流出,那在 data_template_rrd 中就有兩條記錄。
4 、 data_input 那幾張表,主要是數(shù)據(jù)獲取方式,數(shù)據(jù)獲取方式有 6 種,我們一般用的是三種:腳本直接取,就是 script 、 snmp ,給個(gè) oid 直接 get 、 snmp query ,就是 snmp 取回來一組數(shù)據(jù),然后分組。
【編輯推薦】