模板关系说明 【Graph Templates】和【Data Template】存在对应关系。当添加完监控设备后,设备绑定的【Graph Templates】会根据文件名自动去掉主机名称寻找对应名称的【Data Template】。如生成图象[*** Ser ver - ApacheStats08 - Total Hits]就会寻找[ApacheStats08 - Total Hits]数据模板。这里需要特别说明的是,如果监控设备所使用的【Host Templates】创建时有添加任意一个【Data Queries】的话,那最后生成图象的数量可能会有多个,其对应的数据模板依据【Data Queries】配置中的[XML Path]文件。
同时也定义数据收集方法,分别是:
Data Queries
Data Input Methods
数据输入方法(Data input methods),数据模板基于数据输入方法,数据输入方法描述了 Cacti 获取监控数据的各种方法。其中最常用的就是 SNMP,但这里我们要用到一些自定义的模板。 数据查询(Data queries),它是一种特殊的获取监控数据的方式,它所获取的监控数据一般是某一方面的一系列数据,比如网络接口信息。一般包括一个 XML 文件,其中定义了要获取的数据,以及获取方法(一般是一个命令或脚本)。
1、【Data Queries】由【Data Input Methods】组成创建, 通常表现为 XML 格式的文件,并在其[Associated Graph Templates]指向所支持的【Graph Templates】; http://s3.运维网.com/wyfs02/M01/70/F9/wKiom1XCHwqh79D0AAKyQBAuBa0187.jpg
2、【Host Templates】由【Graph Templates】组成创建,也可同时在[Associated Data Queries]绑定【Data Queries】;【Graph Templates】和【Data Template】存在对应关系。
3、【Devices】在添加时绑定【Host Templates】后,其[Associated Graph Templates]处于“Not Being Graphed”状态,点击右上方的[Create Graphs for this Host]进入到界面全选中后启动绘画,状态变更为“Is Being Graphed”开始生效;
4、【Devices】生成画象后,点击[Data Source List]看到【Data Source】,每行【Data Source】记录对应一个【Data Template】以及【Data Template】实例化后的[Supplemental Data Template Data]RRD文件。
下面我们就来看一看如何使用模板?
添加主机模板(Linux / Windows 类似),并添加新主机进行监控
首先,基本上我们使用的所有模板都可以到官方的站点上下载到:
e. 当主机信息填好之后, 点击 Create 。
f. 此时你的页面左上角应该显示: Save Success,并且显示出了主机信息和SNMP信息,如果显示 SNMP error, 则要检查被监控机的snmp状态。
g. 这时我们就可以添加相应的监控项了,在页面最下方的Associated Graph Templates中添加图形模板,在Associated Data Queries中添加数据模板。
h. 添加好相应的模板之后点击Save。此时左上角会出现Save Successful.
i. 点击右上角的Create Graphs for this Host,来为刚才通过模板所获得到的数据进行画图。
j. 选中需要画图的项,其中依然分为两部分:
通过Graph Templates中的内容都需要选中,而Data Query获取的内容比较详细,所以可以按需选择。
k. 选择好需要画图的项目后,点击右下角的Create,左上角会出现被创建出来的画图项。
2.在Graphs Trees 中新添加主机。
a. 在Cacti Web界面Graph Trees中,选择相应的列(或者系统默认的Default Tree)。
b. 进去Tree之后,点击右上角的Add,添加一个新的显示项。
c. 在Tree Item Type中选择Host,然后在下面的Host中选择我们刚才创建的主机。点击Create。
d. 此时,再进入Graphs界面,就可以看到在Default Tree下加入了我们新创建的主机。
Graph Trees -> 选择一个Tree Name -> Add -> Tree Item Type(Host) -> Create
以下是cacti官方文档:
http://docs.cacti.net/manual:087:3a_advanced_topics.1_data_input_methods
任何可以通过脚本来获取数据的设备都可以使用cacti来监控。 步骤一: Creating a Data Input Method
To create a new data input method, select the Data Input Methods option under the Management heading. Once on that screen, click Add on the right. You will be presented with a few fields to populate on the following screen.
When you are finished filling in all necessary fields, click the Create button to continue.You will be redirected back to the same page, but this time with two new boxes,Input Fields and Output Fields. The Input Fields box is used to define any fields that require information from the user. Any input fields referenced to in the input string must be defined here. The Output Fields box is used to define each field that you expect back from the script. All data input methods must have at least one output field defined, but may have more for a script. Data Input Fields
To define a new field, click Add next to the input or output field boxes. You will be presented with some or all of the fields below depending on whether you are adding an input or output field.
When you are finished filling in all necessary fields, click the Create button to continue.You will be redirected back to the data input method edit page. From here you can continue to add additional fields, or click Save on this screen whenfinished.
步骤二: Making Your Scripts Work With Cacti
The simplest way to extend Cacti's data gathering functionality is through external scripts.Cacti comes with a number of scripts out of the box which are located in the scripts/ directory. These scripts are used by the data input methods that are present in a new installation of Cacti.
To have Cacti call an external script to gather data you must create a new data input method,making sure to specify Script/Command for the Input Type field. See the previous section, Creating a Data Input Method for more information about how to create a data input method. To gather data using your data input method, Cacti simply executes the shell command specified in the Input String field. Because of this, you can have Cacti run any shell command or call any script which can be written in almost any language.
What Cacti is concerned with is the output of the script. When you define your data input method, you are required to define one or more output fields. The number of output fields that you define here is important to your script\'s output.
Data input methods with more than one output field are handled a bit differently when writing scripts. Scripts that output more than one value should be formatted like the following:
: : ... :
## Example script output using 3 fields
1min:0.40 5min:0.32 10min:0.01
Note: Spine requires, that multiple parameters are spit out by a single “print” statement. Do not printthem in a loop!
官方文档这样描述: Data inputmethods with more than one output field are handled a bit differently whenwriting scripts. Scripts that output more than one value should be formattedlike the following:
: : ... : 步骤二、在Cacti 上添加数据输入方法(把数据输入方法附加到cacti,通过cacti来周期性的调用它)
【Data Input Methods】 - 【Add】
Please fill in Name, select Script/Command as Input Type and provide the command that should be used to retrieve the data. You may use as a symbolical name for the path_to_your_cacti_installation. Those commands will be executed from crontab; so pay attention to providing full path to binaries if required (e.g./usr/bin/perl instead of perl). Enter all Input Parameters in brackets.
我们看到,cacti已经定义了许多 Speial Type Code。它们类似于宏,我们能够继承它并能够取得相应device相关的信息。我们知道图形和数据收集方法都必须关联到特定的device上,在定义device时,就会指定其hostname等相关信息。如果我们没有提供输入的参数,就让它自动去继承device的那些宏。如果使用hostname,那么此脚本应用到哪个设备上,就会获得那个设备的hostname。如果snmp_community,那么就会自动引用我们在添加设备时,指定的那个community。