| Home Profile Fun |
#180 Linux 24.06.2009
Cacti TipsCacti uses rrdtool to graphically present data for certain timespans. To work with Cacti you should be familiar with the basics of rrdtool and snmp. On this site I have collected some tips and information about aspects of Cacti which remained mysterious for me at the beginning. To make things clearer and to get a nice overview about the relationship between the Cacti objects and rrdtool you find a graphic below. I hope that the information you find here will shorten your learning period with Cacti. Have fun ... Differnce between Data Queries and Data Input Methods Propagation of changes in Templates to their concrete instances Explanations to each of the parts in the tab "console" --- Create New Graphs Management Graph Management Graph Trees Data Sources Devices Collection Methods Data Queries Data Input Methods Templates Graph Templates Host Templates Data Templates --- An example of how data can flow from the monitored host through snmp to Cacti and finally to a Graph Diagram for the overview about Cacti and its relationship to RRDtool: On the left side you see the objects of Cacti and on the right column the rrdtool commands and files. The colors show how they belong together. For example a Graph in Cacti represents a rrdtool graph command in rrdtool. A Data Source in Cacti represents a rrd file. You can see that a Host Template associates a Graph Template and a Data Queries with a Device and builds the Graphs out of it. Nevertheless you can always work without Host Templates and associate Graph Templates or Data Queries directly with a Device. The words Device and host mean the same thing. Depending on where you currently are within Cacti you see one of these two terms. Difference between Data Queries and Data Input MethodsData Queries are used to request index based information about a Device. For example which partitions are mounted. This means that the data you retrieve by this method has always a column which contains the line index, like a database table where you have the index in the first column. Data Queries use Data Input Methods: Get Script Data (indexed) Get Script Server Data (indexed) Get SNMP Data (indexed) Values which are not based on an index, like a single value for example are collected by Data Input Methods. There are six possible types of Data Input Methods: (See "Data Input Methods" -> Add) SNMP SNMP Query Script/Command Script Query Script - Script Server (PHP) Script Query - Script Server The Data Input Methods you can select in a Data Template are the four built-in Data Input Methods: Get Script Data (indexed) Get Script Server Data (indexed) Get SNMP Data Get SNMP Data (indexed)and those which are listed at "Data Input Methods". At "Data Input Methods" you see only those Data Input Methods which have been created additionally. The four built-in ones can't be seen there. Propagation of changes in Templates to their concrete instancesGraph Template -> Graph Changes are propagated automatically Data Template -> Data Source (rrd-Datei) NO change will be propagated! If this is really necessary you have to use rrdtool tune to change the rrd files manually. Usually you delete the Graphs along with their Data Sources and then create the Graphs again. Don't add Data Source Items to existing Data Sources (rrd files)! This is possible in the Cacti front-end but there is no rrdtool command that could do this. Host Template -> Device NO changes will be propagated. Explanations to each of the parts in the tab "console"New GraphsHere you can create one or several Graphs to a Device. (After the creation of the Graphs it takes two polling cycles until you can see the Graphs, usually ten minutes.) Explanation to the drop down list "Graph Types": Above the list you see the Host Template (grey) that belongs to this Device. With the list you can select wich Graph Types shall be displayed for selection. The content of the list is based on the Graphs and Data Queries of the DEVICE, not on those of the Host Template. This means if you have added/removed Graph Templates or Data Queries individually to/from the Device they will also appear here. This would not be the case if just the ones from the Host Templates would be displayed here. All: Shows all Graph Templates and Data Queries belonging to the Device. Graph Template Based: Shows the Graph Templates only. The remaining entries: The Data Queries which belong to the Device. To understand all this have a look at the content of the drop down list. Then go to console -> Devices, select the Device and scroll down. Here you find exactly what also appears at "New Graphs" if you chose "All" in the drop down list. To actually use a Data Query at least one Graph Template must be associated with it. Otherwise you can associate it with a Device but you can't use it for the generation of Graphs. With the drop down list below the Graph Templates it is possible to generate additional Graphs. So you select something here only in case you want Graphs which aren't yet in the list above. The drop down list below the Data Queries (Select a graph type:): If you select a Data Query you always have to chose the right Graph Type here! Graph Type here means Graph Template which have been associated with the Data Query (Associated Graph Templates). So these names don't appear necessarilly in the general list of Graph Templates. In case Data Queries have already been created for the selected Graph Type they are written in grey. This prevents you from creating copies of the same Graphs. But if you want to additionally create another Graph for such an already used Data Query you have to select the desired Graph Type in the drop down list first. Immediately the Data Query can be selected again (if it isn't already used for this Graph Type). Graph ManagementHere the concrete Graphs are listed. Also you can create Graphs individually or based upon a Graph Template. If you chose a Graph you see the Graph itself and which Graph Template has been used for it and to which host the Graph belongs to. Furthermore there is some additional information: Graph Item Fields: the Data Sources which deliver the data for the Graph. Graph Item Fields represents here the Graph Item Inputs in the Graph Template ( see console -> Graph Templates, select a Graph Template). Graph Management -> CDEFs CDEFs allow to manipulate the data which comes from the rrd files to generate the Graphs. For example you could decide to change the values so that you see bytes/second instead of bits/second in the Graph. DEFs are variables in rrdtool graph commands which contain the values from the selected time of the request. CDEFs are descriptions of mathematical operations which are applied to values of DEFS. (Also see the CDEF tutorial from Tobi Oetiker) Here you can easily click together any CDEF and finally use it with the Graph Template Items in the Graphs or Graph Templates. Graph Management -> Colors This is for generating new or changing existing colors. Just enter the desired HEX code and you see the result. This can then be used for Graph Items, e.g. lines, legend, comments, etc. Graph Management -> GPRINT Presets GPRINT Presets are used to display values of a Graph in the legend in a certain format (similar to printf). An example is the Graph Template "UNIX - Load Average". If you chose it you see all the Graph Template Items on the top. In the middle of the table is a column called "Graph Item Type". Here you see that Item 2, 4 and 6 is of type GPRINT. These three items use the GPRINT Type "Load Average". Together with the current values of the load average they form the legend below the Graph. If you look at the configuration of the GPRINT Preset "Load Average" you see the name and the format: %8.2lf (2 decimal places). Graph TreesThe presentation of Graphs on the graphs tab is in the form of trees. Here you can add or remove Graphs at any place in the tree. It is also possible to create several trees. There are three elements available to add to the tree: Header, Host or Graph. Header: Creates a sub tree Host: Adds all Graphs of a host Graph: Adds a single Graph You can chose from several order functions: Manual Ordering (No Sorting) Alphabetic Ordering Natural Ordering Numeric Ordering [root] means root within the selected tree not root in relation to all trees. Data SourcesData Sources represent real rrd files. If you select a Data Source you see which Data Template has been used to create this file and to which host it belongs. You see also the exact path in the file system to this rrd file. You can create new rrd files here by selecting the desired Data Template and host. Data Sources -> RRAs RRAs define how the data is stored. For example this can be average or maximum or how many PDPs (primary data points) are used for one CDP (consolidated data point). See rrdtool for details. DevicesHere you find all the registered hosts and of course you can add or remove hosts. For a new host you have to provide its hostname or its IP address. If you associate a Host Template to this host you can see below all the Graph Templates and Data Queries which belong to the Host Template. And that's great because you can now easily create the same Graphs for all hosts with the same Host Template. If you don't chose a Host Template for the host the lists for the Graph Templates and Data Queries remain empty. But you can always add those manually. In both cases you can always add/remove Graph Templates and Data Queries for a host. If you want to change the Re-Index Method for a Data Query just delete it again add it by chosing another Re-Index Method. If you directly look at the Host Template you have chosen for the host you can exactly see the below listed Graph Templates and Data Queries. Data QueriesEach Data Query uses a XML file and a Data Input Method. Every Data Query musst have at least one Graph Template associated with it. Otherwise it is not possible to generate Graphs with this Data Query. The XML file is used to present index-based data coming from snmp requests in Cacti so that the user can select which parts are of interest for him. It means for example you get the data of the mounted partitions. You can select in Cacti which partitions you are interested in. Then only the values of these partitions will be stored. The distinction is made by the tag "direction" in the XML file. If you associate a Graph Template to a Data Query you can give the Graph Template a separate name. Therefore the names of the Graph Templates you see in the Data Query don't necessarily appear in the general list of the Graph Templates. But in the second column you can see the actual name of the Graph Template. Also see above "Differnce between Data Queries and Data Input Methods". Data Queries -> Associated Graph Templates Not until you add a Graph Template here the Data Template with Data Source and Suggested Values will be associated. Data Queries -> Associated Data Templates Generally it is only possible to associate Graph Templates with a Data Query. If this is done and you select the Graph Template you see fields which belong to the associated Data Template. But where do these fields come from? The answer is: through the Graph Template respectively its Graph Template Items. Data Queries -> Associated Data Templates -> Data Source This line contains the name of the Data Source of the Data Template and a drop down list which has exactly the output fields of the XML file of the Data Query. Data Queries -> Suggested Values (Graph Template) What you find here belongs to the direct properties of the Graph Template, e.g. the title. It is used to distinguish Graphs which belong to the same host. Data Queries -> Suggested Values (Data Template) What you find here belongs either to the direct properties of the Data Template, e.g. name or it belongs to the properties of the Data Source Items of the Data Source of the Data Template. For example rrd_maximum. It is used to distinguish the different Data Sources which belong to the same host. Data Queries -> Data Input Method Here you can select only the index-based Data Input Methods because Data Queries are used to retrieve only index-based Data: Get Script Data (indexed) Get Script Server Data (indexed) Get SNMP Data (indexed) Data Input MethodsHere you see the currently existing Data Input Methods. Each of them is based on one of six types. As soon as you click "Add" you have to chose one of these types for the new Data Input Method. For the type Script/Command the field "Input String" needs the full path to the script, if necessary with parameters, e.g. "<path_cacti>/scripts/diskfree.sh <partition>". The parameters you put in this field can then be selected at Input Fields -> Add. Similarly for every return value of the script you have to define an entry in "Output Fields". Now, if you create a Data Template you have to selected the appropriate Data Input Method. If you then add a new Data Source Item to this Data Template you can select in the field "Output Field" exactly those records which have been defined in the Data Input Method as "Output Fields". Also see (Differnce between Data Queries and Data Input Methods). Graph TemplatesGraph Template Items define which Data Sources shall be printed on the Graph. As soon as you add a Graph Template Item to a Graph Template and you select the Data Source for it this Data Source will be added automatically as a Graph Item Input. When you create a Graph the Graph Item Inputs allow you to use individual values for Graph Items which differ from the Graph Template. An example: you chose a color as a Graph Item Input and you associate it with item1 (or more items). If you create a Graph for a Device based on this Graph Template you see those Graph Item Inputs there. In case of a color you get a list of possible colors to chose from. This color will then be applied only for this particular Graph. If you click on the Graph Template Item in the Graph Template you see in the area color an additional entry: [Field Not Templated]. If you click on it you get exactly to the configuration of the corresponding Graph Item Input. The drop down list "Field Type" at the Graph Item Inputs contains the possible fields of the Graph Template Items. If you look at one Graph Template Item you see the following fields top down: Data Source, Color, Opacity/Alpha Channel,... Graph Templates -> Graph Template Item -> Graph Item Type Comment HRULE VRULE LINE1 LINE2 LINE3 AREA STACK GPRINT LEGEND Graph Templates -> Graph Item Input -> Field Type Data Source Color Opacity/Alpha Channel Graph Item Input Consolidation Function CDEF Function Value GPRINT Type Text Format Insert Hard Return Host TemplatesThese are collections of Graph Templates and Data Queries which can be connected with a Device. This way you can associate the same Host Template to all members of a group of Devices, e.g. all Cisco routers. The result is that you get all your Graphs for a Device just by using the desired Host Template. But a Host Template does not force such a structure onto a Device. It is always possible to add/remove Graph Templates and Data Queries to/from a Device. Data TemplatesA Data Template represents a skeleton for a rrdtool create command. The Data Source Items represent the DS lines in the rrdtool create command. The selectable RRAs represent the RRA lines in the rrdtool create command. If you create a new Data Template you should activate the checkbox which is at the name of the Data Source (Use Per-Data Source Value (Ignore this Value)). The name should start with |host-description|. Otherwise you can't see which of the Data Sources (rrd files) derived from this Data Template belong to which host. They all had the same name. A Data Template can contain several Data Source Items. This is needed in case a script returns data in parallel. Also for Data Queries it is needed. Data Template -> Output Field The drop down list "Output Field" appears in the area Data Source Item only if the Data Input Method has corresponding fields defined, see for example "Unix - Load Average". Data Template -> Custom Data What appears here depends on the Data Input Method. These are the fields that have been defined at the Data Input Method as Input Fields. For example if you associate a Data Input Method which is of type SNMP with this Data Template you can enter here the OID, snmp version, etc. Is the type Script/Command you can enter values here which will passed to the script or command if parameters have been defined in the Data Input Method. In case you have entered a Special Type Code in the Input Fields of the Data Input Method, e.g. snmp_community, you will see here "Value will be derived from the host if this field is left empty". This means that the value for this field will be determined from the Device configuration. An example of how data can flow from the monitored host via snmp to a Graph in Cacti:Value/parameter on the host -> A table as the result of a snmp request -> Definition of table columns in the XML file -> Data Source Item / rrdtool create statement (DS entry) -> Graph Template Item -> Graph Nagios and Cacti Cacti Training |