Cacti table structure and data passive acquisition

Source: Internet
Author: User
Tags rrd rrdtool snmp query cisco switch

Cacti we also used for a long time, but its table structure has not been to care about, hollow smoked half the night time, the library table structure is probably looked under, some of the meaning of the field to share with you:
Cacti data are stored in the RRDtool, database storage is actually only configuration data, cacti logical objects are mainly divided into three kinds of data, graph (picture), host (device), which in its table design can also be easily seen. So, there are three big categories to discuss.

First, Host
Cacti's host is to use the template, each host's own information, only stored in the host table, the rest of the template is the information, the corresponding relationship between the template and so on.
1. Host table
The host table has 34 fields to hold the device information, which we can see and configure in the Devices option in the console. The specific fields have the following meanings:
ID: is the ID of the device, self-increment
HOST_TEMPLATE_ID: If the device uses a template, then this is the ID of the template
Description: Description, device name seen in cacti
Hostname: Device IP Address
NOTES: no explanation.
Snmp_community, Snmp_version, snmp* ... : SNMP-related configuration options, meaning literally
Availability_method: On the page to see is downed device Detection, I understand is, how to see if this device hangs
PING_METHOD:UDP Ping or ICMP, or TCP
Ping* ... : Ping related options, literal meaning
Max_oids: The maximum number of OIDs to get at a time
Status* ... : Device current state-related, literal meaning
A bunch of time: not very clear, should be pollor related, specific units do not know
Total_polls: How many times are the values taken?
Failed_polls: How many times have you failed?
Availability: availability, calculated from the above two fields
2. host_template table
Device template, a total of three fields, the first is the ID, is host_template_id, in the host table has a reference, the second is a hash, is the template location index, the third is the index name.
3. Host_template_graph table
The correspondence of the template, storing the information is mainly, a device template, need to draw what diagram, that is, the corresponding relationship between the device template and the drawing template, on two fields, host_template_id and Graph_template_id,graph_template_ The ID is the ID value inside the graph_templates.
4. Host_template_snmp_query table
The corresponding data fetching method is snmp_query_id, the ID value of the Snmp_query table.
Each snmp_query, will have graph, if a device template, corresponding to a snmp_query, the snmp_query corresponds to a series of graph, the device template will automatically correspond to these graphs, and this relationship in Host_ There's no template_graph.
5. Host_graph table
The counterpart of the device and picture template is also two id,host_id and graph_template_id,graph_template_id defined in the Graph_templates table.
In general, the image under this device will contain the corresponding device template and picture template, which means that this correspondence is similar to the Host_template_graph table.
6. Host_snmp_cache Table
The temporary value when storing SNMP to fetch value, such as network traffic, need to be accumulated value, then this is the last total, used to calculate the
7. Host_snmp_query Table
The correspondence between the device and the snmp_query, similar to the host_graph, corresponds to the data in the Host_template_snmp_query table.

Second, Data
Data is primarily the acquisition, the acquisition of data, and then stored in the Rrd file, where the data stored here is mainly how to obtain data, and how to store the data of the two.
1. Data_input table
The way data is obtained is seen in the Data_input_method in the console.
ID: The ID of the data acquisition method
Hash: The corresponding disk index
Name: Names of data acquisition methods
Input_string: If it's a script, that's where the script is.
Type_id:type has not found the corresponding table, it may be written in the program is dead, corresponding to the Input_type, there are 6 options, namely: SNMP, SNMP query, Script/command, script query, script– Script server, script Query–script server
2. Data_input_fields table
This table is used to store some of the objects required in the Data_input method, such as the OID SNMP, which is an object, when the script takes the hard disk, retrieve the value of the name, Unit, belongs to its defined category. Table content, mainly these objects, and the corresponding data_input.
ID of the Id:input_fields
DATA_INPUT_ID: The ID in the corresponding data_input table
Name, Data_name: Names
Input_output: Input or output
I don't know the next few fields ...
3. Data_input_data table
The Data_input_field content of each data object is stored.
ID in the Data_input_field_id:data_input_field
ID in the Data_template_data_id:data_template_data
4. data_local table
Storing the data object is what you see in the console's data source page. But this table is just a simple definition of an object and a corresponding relationship, the object's specific properties are in another table.
ID of the Id:data
DATA_TEMPLATE_ID: Which data template is used, defined in the Data_templates template
HOST_ID: Which device's data is defined in host
SNMP_QUERY_ID: If it is obtained by Snmp_query Way, the ID of the corresponding snmp_query, if not, is 0
Gets the prefix of the array when the Snmp_index:snmp_query method gets the data. For example, in traffic acquisition, the Port's index
5. Data_template table
Data template, which we see in the console's data templates.
ID: ID of the data template
Hash: Index
Name: Names
6. Data_template_data Table
Information about the specific data object, including the template. It can be assumed that each object represents an RRD file.
ID of the Id:data object
LOCAL_DATA_TEMPLATE_DATA_ID: If a template is used, this is the ID of the template, and the location defined is the table
LOCAL_DATA_ID: The corresponding data object, defined in the Data_local table
Data_template_id:data_template, data templates, defined in the Data_template table.
DATA_INPUT_ID: How data is obtained, defined in the Data_input table
*name: The name is the literal meaning
Path to the Data_source_path:rrd file
T_*: I don't know ...
Active: Whether it is activated, can be controlled by enable/disable
Rrd_step: Step, default is 300s, is 5 minutes, that is, how long to save a data (rrdcreate option)
7. Data_template_data_rra Table
The correspondence of data object and RRA, RRA is also the concept in RRDtool, it is a mechanism of data archive compression.
DATA_TEMPLATE_DATA_ID: ID defined in the previous table
RRA_ID: The ID of the corresponding RRA, defined in the RRA table
8. DATA_TEMPLATE_RRD Table
Basically also rrdtool configuration option, an RRD file can be stored in multiple columns, called DS, each column represents a set of data. This table can be seen as a definition of this column.
ID of the Id:ds
LOCAL_DATA_TEMPLATE_RRD_ID: If you use the DS template, the ID of the template is defined here, and the template definition is in this table
LOCAL_DATA_ID: Data ID, defined in the Data_local table
DATA_TEMPLATE_ID: The data template used, defined in the Data_template_data
The rest is rrdtool when creating the Rrd file, the configuration options for this DS, such as the maximum value, the name, and so on.
The data section is still more complex, and if it's even with host, it's more complicated. Aside from the template is not discussed, generally speaking, there are the following correspondence:
1, each host_id, has a set of local_data_id, for example, a Cisco switch CPU is a local_data_id, one of its ports--TE1/1 traffic, is also a local_data_id. A host_id corresponds to multiple local_data_id.
2, each local_data_id, is a data source, it must have an rrd file corresponding to him, so each local_data_id in Data_template_data, must correspond to a row of records, there must be an RRD file. Although there are so many records in Data_template_data, where the local_data_id is 0, or the RRD path is empty, that is the template.
3, each RRD file, must have at least one DS, that is, in data_template_rrd, at least one record, such as traffic, or Cisco switches, each port represents a local_data_id, there is an RRD file, there are two ds, inflow and outflow , there are two records in the DATA_TEMPLATE_RRD.
4, data_input that a few tables, mainly data acquisition methods, data acquisition methods have 6 kinds, we generally use three kinds: script directly take, is scripts, SNMP, to an OID direct get, SNMP query, is SNMP retrieve a set of data, and then group.

Third, Graph
In the drawing aspect, the custom method actually many, cacti did not put rrdtool in the drawing aspect the parameter All to show out, but also already enough.
1. graph_local table
Local pictures, and data_local similar, generally speaking, a Data_local object, will correspond to a Graph_local object, meaning, a data, corresponding to a picture, but there may be no corresponding situation, that is: I have some data does not draw, Or some diagram I need multiple data.
The table structure is similar to data_local, but data_template_id is replaced with graph_template_id, and the first ID field represents a change in meaning, representing the graph object.
2. graph_templates table
The drawing template.
ID: ID of the template
Hash: Index
Name: Names
3. Graph_template_input table
Graph_template corresponds to the specific object type, such as the type is a color, this type is the flow of data into the data source, and so on.
ID: ID of the data type
Hash: Index
GRAPH_TEMPLATE_ID: ID of the picture model, defined in Graph_template
Name: Names
Description: No explanation.
COLUMN_NAME: The type of object, whether it is a color, a data source, or a paragraph of text
4. Graph_template_input_defs table
Defines the specific object type in the diagram and the corresponding item.
Graph_template_input_id:graph_template_input ID, what type is
GRAPH_TEMPLATE_ITEM_ID: ID of the specific object, defined in Graph_templates_item
5. Graph_templates_gprint table
Output format
6. Graph_templates_graph Table
The options at the time of drawing, each map in this table corresponds to a record, mostly RRDtool parameters. Similar to the data_template_data.
ID: The ID of the drawing option
LOCAL_GRAPH_TEMPLATE_GRAPH_ID: If you use a template, this is the ID of the template. What is defined in the template does not have to be redefined. There are definitions in this table
LOCAL_GRAPH_ID: Which map is defined in graph_local
GRAPH_TEMPLATE_ID: Drawing templates defined in the Graph_templates table
The rest are the RRD drawing options, such as how high the picture is, how wide, what the name of the image is, etc...
7. Graph_templates_item Table
Each picture, corresponding to what the content. The content is mainly composed of: line or polygon, that is, the trend chart, the following labels, such as the maximum value, the minimum value, the current value.
ID of the Id:item
Hash
LOCAL_GRAPH_TEMPLATE_ITEM_ID: If a template is used, the ID of the write template is defined in this table
LOCAL_GRAPH_ID: Which map the object belongs to
GRAPH_TEMPLATE_ID: Drawing templates defined in the Graph_templates table
TASK_ITEM_ID: If the type of the object is task_item_id (defined in graph_template_input), then the ID here is the ID of the data source, defined in DATA_TEMPLATE_RRD.
COLOR_ID: color, defined in the color table
Alpha: Transparency
GRAPH_TYPE_ID: What is the type of diagram?
CDEF_ID: If the value is calculated (for example, the accumulation of multiple values), then there is a calculated formula, defined in the Cdef table
CONSOLIDATION_FUNCTION_ID: function functions, such as averaging, taking maximum value, etc.
Text_format: String, directly displayed on the diagram, can be understood as the name of the object
Value: Values
Hard_return: I don't know.
GPRINT_ID: Output format
SEQUENCE:RRD drawings are sequential, sequence large objects overwrite sequence small objects
The place of drawing is the most complicated place, because the RRDtool itself is the most and the most complex in drawing, and it is very complicated to encapsulate these things into the database. In general, this can be understood as:
1, each host_id object, can correspond to multiple graphs, but there may be some diagrams do not correspond to any host, such as a summary of the graph. But every picture must be defined in graph_local, there is a local_graph_id.
2, each picture, when created must have many parameters, these parameters are defined in the graph_template_graph. If a template is used, the parameters defined in the template are not duplicated.
3, each picture, must contain more than one object, that is Graph_template_item, item has many types, for example, the flow graph, the green area represents the outflow, the blue solid line represents the outflow, respectively represents an object. There are also objects, such as the maximum value of the subscript, the average, and so on. These objects, which need to have a data source, may be a data source, may also require more than one, because the actual plotted value, is cdef the different data source operation after the resulting. This data source is the DS, which is the object in DATA_TEMPLATE_RRD.

Iv. cacti How to achieve passive data acquisition
After understanding its data structure, we can find a way to achieve the passive acquisition of cacti data, because not all occasions, SNMP can take the data, perhaps sometimes we want to take the IP in another LAN, perhaps we think cacti load is too high, can not let it take too much data.
1, the way
The way is very simple, define the host,data,graph in cacti, and then as long as we can regularly insert the data into its RRD file is OK.
2. Methods
Methods can have two types:
The first script, cacti supports self-writing scripts to fetch data. The best way to do this is to periodically push the data to the cacti machine, append it to a file, and cacti read the file through a script to get the data.
The second is to directly plug in the RRD file, cacti the normal way to get data is to use crontab run poller, or spine, to the timing to fetch data. We do not need to get the data in the process of poller or spine, skip directly, and periodically push the data in from the outside, then insert the RRD file.
3. Steps
A, add a host (if the host is unreachable, the availability check will fail, but it's okay)
b, to add a data source, you need to insert the following tables: Data_local, Data_template_data, Data_template_data_rra, DATA_TEMPLATE_RRD
C, create the RRD file, open the Data source page, you should already be able to see the source we added, open the debug mode of the data source, copy the RRDtool command to the shell to execute once (attention to permissions)
D. To create a picture, insert the following tables: Graph_local, Graph_template_graph, Graph_template_item
E, timed to insert data into the RRD file (in the way you like, also pay attention to the RRD file permissions)

Cacti table structure and data passive acquisition

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: info-contact@alibabacloud.com 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.