Cacti templates (graphical templates, data templates, host templates) and custom monitoring scripts

Source: Internet
Author: User
Tags rrd rrdtool

Cacti defines three types of templates:

  • Host Template

  • Data Template

  • Graphic Template

Host templates)It is a collection of image templates and data queries. It describes the images that need to be generated by monitoring a certain type of machines.

Data templates)Which describes the data stored by cacti to the specified type of RRD file. This template is related to the CREATE command of rrdtool.

Graph templates)Describes what the generated image looks like. Which data templates are used, which elements are displayed, and whether cdef is used for calculation and summary.

The data collection method is also defined:

Data Input Method)The data template is based on the data input method. The data input method describes various methods for cacti to obtain metric data. The most common one is SNMP, but here we need to use some custom templates.

Data Queries)It is a special way to obtain monitoring data. The monitoring data it obtains is generally a series of data, such as network interface information. It generally includes an XML file, which defines the data to be obtained and the method to obtain the data (usually a command or script ).

In actual work projects, we may need to monitor more metrics. What should I do now? In fact, the cacti official website provides many templates, and many volunteers also provide a large number of templates. We can download, decompress, import, and use them directly.

On the cacti official website-> forums-> scripts and templates, the templates here are all available and can basically meet our monitoring needs.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qccwizs3tgaaijpsazey0162.jpg"/>

Let's take a look at how to use the template?

Add a host template (similar to Linux or Windows)

First, basically all templates we use can be downloaded to the official website:

Http:// F = 12 & SID = fe2532345bf037678cb1e9fb07b40f16


When we download a template,Please carefully read its installation (very important) to avoid many unnecessary errors.. For example, download Then, the author provides detailed installation instructions:

  1. Unzip the download

  2. Via cacti Web Console, click on "Import templates" and import the file "cacti_host_template _ *. xml"

  3. Create new device using the new imported host Template

  4. Check new Graphs

OK. Let's demonstrate how to add and use a template.

1. Add a template

Import templates-> browse-> import, and then OK.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1poz2iwd6hkaalyeq3nxci071.jpg"/>

2. Use a template

Add a device: devices-> Add, and then edit the device in two places.

  1. General host options

  2. SNMP options

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1poaociiogcaahuc1r1ivs529.jpg"/>

Create a graph for the host

650) This. width = 650; "src =" "Title =" 1.png" alt = "wKioL1Poau7BLh-1AAI2scir3aQ921.jpg"/>

Then, select the images to be created:

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1poalkd0qucaagmqrwceug323.jpg"/>

Then, add the device to graph trees to facilitate management.

Graph trees-> select a tree name-> Add-> tree item type (host)-> Create

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1pobq3hmcwuaaibxs3ovkm989.jpg"/>

That's easy, so it will be shown later.

Add a graphic Template

The import method is the same as that of the host template. After the import, you can view it in Console> templates> graph templates.

Let's take cacti_graph_template_linux_server_-_processes.xml.gz as an example to demonstrate how to add and use a graphic template. Download and view its installation.

  • Unzip the file

$ gzip -d cacti_graph_template_linux_server_-_processes.xml.gz
  • Use console-> Import/Export-> Import templates to import the XMLFile

Here, the import process is not demonstrated, and the process is the same as the process for importing the host template above.

How can I apply the added image template to a specific host?

Graph management-> host label select a host-> Add-> selected graph template-> Create

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1poe2cc0ztdaafjhqanjlw657.jpg"/>

HowHostHow can I delete the added image template?

Graph management-> select host-> select-> then choose an Action: Delete

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qb4nechunpaat0hjeg8fo597.jpg"/>

In the next step, select the first option, retain the data source, and delete only the graphic template.

650) This. width = 650; "src =" "Title =" 2.png" alt = "wkiol1qb4rshy5rxaae_f1qpduc917.jpg"/>

Cacti custom monitoring script

What should I do if I cannot find a suitable template on the cacti official forum? At this point, we may need to customize it.

As mentioned in the previous article. There are two main cacti data collection methods:

  • Data Queries is mainly a defined XML file.

  • Data input methods is mainly scripts and command (most commonly used)

The detailed process of monitoring by using the cacti custom monitoring script is as follows:

  1. Custom Data collection methods, scripts (XML, scripts, command)

  2. How to save the collected data? Data Template. The data template defines how to get data through the data collection method, how to save the acquired data, and where it is saved. (That is, calling rrdtool create and rrdtool update)

  3. Apply the data template to a specific device to create a data source.

  4. With the data source, you can draw. Apply a graphical template or custom template to the corresponding data source. (Rrdtool graph)

The following are official cacti documents:


Any device that can obtain data through a script can use cacti for monitoring.

The following describes the process of custom monitoring.

1. Create a data collection script

[[Email protected] ~] # Vi tcpconn. Sh #! /Bin/bash # $1: hostname or IP # $2: SNMP communityif [[$ #-ne 2]; thenecho "Usage: $0 [hostname | IP] snmp_community "exitfisnmpnetstat =/usr/bin/snmpnetstatestablished =$ ($ {snmpnetstat}-v2c-C $2-can-cp tcp $1 | grep- I 'established' | WC-l) echo-n "Established: $ established" # Add executable permissions to the script # chmod + x tcpconn. sh ## copy the script to the scripts directory in the cacti installation directory (important) # cp tcpconn. SH/web/cacti/scripts/

Note:: The output format of the data collection method is special, and the rule must be as follows.

The official documents describe data inputmethods with more than one output field are handled a bit differently whenwriting scripts. scripts that output more than one value shoshould be formattedlike the following:

<fieldname_1>:<value_1>  <fieldname_2>:<value_2>  ...  <fieldname_n>:<value_n>

2. Add data collection methods on cacti

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb6dltbwrmaajmty4rhvo786.jpg"/>

Next, enter the corresponding information.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qb7bobclhgaahsj8mtoqo977.jpg"/>

How can we execute our script? /Bin/bash. What is the specific script path? <Path_cacti> can be referenced. Our script needs to pass parameters. How should we pass them?

  • <Path_cacti> is a macro that references the cacti installation directory.

  • If the script needs to accept parameters, use <> to enclose them.

Click "CREATE". The input fields and output fields below correspond to the parameter input and Script output respectively.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wKiom1QB6-_SI2HAAAF10ydCyBg347.jpg"/>

You need to add several input fields, and add multiple output fields.

Add input fields

650) This. width = 650; "src =" "Title =" 1.png" alt = "wKiom1QB7S-T2VQ7AAIiwllJqbM909.jpg"/>

We can see that cacti has defined many speial type codes. They are similar to macros. We can inherit them and obtain information related to the corresponding device. We know that graphics and data collection methods must be associated with a specific device. when defining a device, we will specify its hostname and other related information. If the input parameter is not provided, let it automatically inherit the macros of the device. If hostname is used, the hostname of the device is obtained when the script is applied to the device. If snmp_community is used, the specified community is automatically referenced when the device is added.

For example, when defining a device, enter the following information:

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qb7zfxirpbaamfgwfxb4c401.jpg"/>

In this case, special type code: Hostname =, snmp_community = Public

Add output Fields

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb7_qbif69aaelxdow4o4625.jpg"/>

Note: When we receive a data record, We need to update the RRD file. Therefore, you must check "Update RRD File.

3. Define a Data Template

In the previous step, we defined the data collection method. How can we save the collected data? Where is it stored? How to create an RRD file? These are all completed by the data template, so we need to define the data template next.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb8sohnl6qaaj8ifrhg3w135.jpg"/>

Then, for the following definition, we can fill it out by referring to other data templates. If you do not know how to fill in this definition, you may first look at how other data templates are defined.

We can see that the name is special here "| host_description |", so that the description of the device can be automatically obtained. And "Internal data source name", the name of the data source, note its naming rules, a_zA_Z0-9 _, and no more than 19 characters.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb84arigoyaalm?mmxck685.jpg"/>

4. When we apply a data template to a device, we create a data source)

Note that the data source must be associated with a device. We must specify the host and then add

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qb9bpj6ekeaac3ezlljxm886.jpg"/>

Then select the corresponding data template (We just added) and the host to be associated.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb9rsir8ymaadpoilski8202.jpg"/>

After this step is completed, the corresponding RRD file will be created.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qceivd_oioaafz4gzfyya553.jpg"/>

Of course, the "Data Source Path" here can be named as needed. Wait for a moment and the RRD file will be created in the/web/cacti/RRA directory.

5. Add a graphic Template

For more information, see other templates.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qb9djc_u97aagkdzax3rm304.jpg"/>

Enter the basic information (name, title) about the image. Retain the default information or enter the basic information as needed. After clicking "CREATE", we need more detailed settings.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wKioL1QCev7h4eUAAAE-dwuxvq0546.jpg"/>

What is "Graph item? A graphical item is equivalent to a line, area block, comment, and other elements on a graphic. Each item represents an element.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qcfdhdgi0oaamkuvlmqqs779.jpg"/>

Then add "Graph item inputs"

650) This. width = 650; "src =" "Title =" 1.png" alt = "wKioL1QCgaOi2H-HAABHQJdGdFY852.jpg"/>

6. Associate the image template with the device

Console-> graph management-> specify host-> Add

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qcfupcvswbaanp1bdygow360.jpg"/>

Now, we have finally done it.

What should I do if I want to display the following results?

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qcf8rtl1hkaacmqxn2hls395.jpg"/>

Reedit our graph templates and click the Template Name we want to change:

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiol1qcgcdj41o5aac6g9fsqyw412.jpg"/>

In the following settings, select "Graph item type" and set it to "uplint.

650) This. width = 650; "src =" "Title =" 1.png" alt = "wkiom1qcgtcjnfnvaajcncjsyao550.jpg"/>

OK. Let's talk about more advanced functions and hope you can explore them.


In our operation process, our thinking is clear, but we don't know how to deal with many options. If you know rrdtool, none of these are things, if you don't understand it, it may seem quite painful, because you don't know what to do? We recommend that you see how rrdtool works.

This article is from the share your knowledge blog, please be sure to keep this source

Cacti templates (graphical templates, data templates, host templates) and custom monitoring scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.