cacti脚本数据采集
脚本对接方式有两种方法,一个是直接将脚本放到script目录里,然后添加相应的数据查询方法、创建数据模板图形模板即可。二个是在每台主机内放置脚本,然后自定义OID,然后创建模板,即可。
优缺点:
优点:支持非SNMP数据源,可以返回多个数据,灵活性强
缺点: 操作相对复杂,会写脚本
步骤:
1.编写脚本
示例:<path_cacti>/scripts/diskfree.sh
2.配置Data Input Methods
input type选择script/Command,
3.配置数据模版
4.配置图形模版
5.图形模版应用
编写脚本:
若你想使用脚本来采集数据,你需要建立数据输入方法(data input method),并保证在输入类型(Input Type field)中选择script/command.
你要定义一个或多个输出字段:
当只有一个输出字段时,输出格式:
<value_1>
Example script output using 1 field
67
多输出字段时:
Example script output using 3 fields
1min:0.40 5min:0.32 10min:0.01
示例:
1.编写脚本
vim my_ip_conn.sh
#!/bin/sh
host=$1
ip_conns=`ssh $host "netstat -an | grep tcp | grep EST | wc -l"`
echo $ip_conns
2.配置Data Input Methods
Console/Data Input Methods/data inputmethod:
填写:
name:zz_ip_conn
Input Type:script/command
Input String: #(指定脚本位置及data source,如ip)
sh <path_cacti>/scripts/my_ip_conn.sh <hostname>
#eg.python <path_cacti>/scripts/python_rrdb_test.py <host> <port>
填写完毕后: 单击Create,继续完成input fields,output的填写
Input Fields :(输入字段)
The Input Fields box is used to define any fields that require information from the user.
若你需要当前主机ip, 你可使用 'management_ip' here and Cacti will fill this field in with the current IP address of the selected host.
输出字段: (和脚本的输出字段名要完全相同)
In Cacti, I name the output fields '1min', '5min', and '10min', respectively. Based on these two things, the output of the script should look like the following:
3.配置数据模版
Data Templates
Second, you will notice a list of data source/data source item field names with Use Per-Data Source Value checkboxes
next to each one. The nice thing about templates in Cacti is that you can choose whether to template each field on
a per-field basis. If you leave the checkbox unchecked, every data source attached to the template will inherit its value from the template. If the checkbox is checked, every data source attached to the template will contain its own value for that particular field. When generating a real data source, you will be prompted to fill those non-templated fields.
填写以下内容:
1).Name 第一个 Name 是模板的名称 , 可自定义设置 , 填写 "zz_ip_conn_data_templ" ;
2).Name 第二个 Name 是数据源的名字 , 再此填写 "zz_ip_conn_data_templ ;
3).Data Input Method 获取数据的方法 , 选择 刚才定义好的数据输入方法 "zz_ip_conn" ;
" save ” 保存数据源。
Pay attention to not append new Data Source Items to already existing rrd files. There's no rrdtool command to achieve this!
Second, you will notice a list of data source/data source item field names with Use Per-Data Source Value checkboxes next to each one.
The nice thing about templates in Cacti is that you can choose whether to template each field on a per-field basis.
If you leave the checkbox unchecked, every data source attached to the template will inherit its value from the template.
If the checkbox is checked, every data source attached to the template will contain its own value for that particular field.
When generating a real data source, you will be prompted to fill those non-templated fields.
数据模板的一个优点是你可选择是否给每个输入字段使用模板,若你不选中Per-Data,每个使用该模板的数据源(data Source)将使用继承自模板的数值,若勾选Per-Data,每个数据源将为输入字段使用自已的数值.这样多你产生一个实际的数据源(),你将被提示要填写相应的非模板字段数据。
Data Source Items:
一个数据源可以用多个数据值,
Like a graph, a data source can have more than one items. This is useful in situations where a script returns more than piece of data at one time. This also applies to data queries, so you can have a single data template that contains both inbound and outbound traffic, rather than having to create a separate data template for each.
Custom Data
用户数据,若你选择了数据输入源,则会出现以接受参数.这就是数据源把数据输入方法和运行参数结合起来的过程~This is how the Data Source glues together with the data input method to provide all run time parameters.
Assuming you selected a data input source on the previous screen, you should now be presented with a Custom Data box.
It will show a single line for every single parameter required for that very data input method.
This is how the Data Source glues together with the data input method to provide all run time parameters.
Each custom data field is per-field templatable as all of the other data source fields are.
Even if you select the Use Per-Data Source Value checkbox,
it might be useful to specify a value that will be used as an "inital value" for any data source using this data template.
参考:http://www.51cacti.cn/cacti/templates.html#DATA_TEMPLATES
4.配置图形模版
填写名字等后 单击create
添加Graph Items
Graph Item Inputs
After creating graph items for your template, you will need to create some graph item inputs. Graph item inputs are unique to graph templates because of the large number of items they sometimes contain. Graph item inputs enable you to take one graph item field, and associate it with multiple graph items.
5.图形模版应用