RRDtool Learning and Customizing script drawing graphics Memo

Source: Internet
Author: User
Tags rrd rrdtool

RRDtool (Round Robin Database tool) is a powerful drawing engine, and many tools, such as MRTG, can call RRDtool drawings. Including the use of a lot of cacti is also based on the rrdtool basis of drawing, can say cacti just provide a display graphics Web page.

RRDtool: So-called round robin refers to a ring-shaped database: The data is stored in a ring form, and we can define for ourselves how long the data can be stored and how much space is given to it. When our space fills up, the data in the back can overwrite the previous data. So the RRDtool database is not going to grow. (but we also need to understand a truth.) Since the data fills up and overwrites, then we define it more as well): Create a database generic name we all define the suffix file for. rrd. (as shown:)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/70/wKioL1SCqYrDwzDuAABN5_fZ8No588.jpg "title=" Doughnut chart. png "alt=" wkiol1scqyrdwzduaabn5_fz8no588.jpg "/>

The main understanding of the concept: with a picture description:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/70/wKioL1SCszjThxzIAADH8erG7aw005.jpg "title=" RRD picture. png "alt=" wkiol1scszjthxziaadh8erg7aw005.jpg "/>

  • The ds:ds is used to define the Data soure. That is, the variable name used to hold the result. DS is used to declare the data source, but also can be understood as the declaration of data variables, that is, you want to detect the port corresponding to the variable name, this parameter is used when drawing.

  • DST:DST is the type of DS. There are 5 kinds of COUNTER, guage, DERIVE, ABSOLUTE and COMPUTE. Because the network card traffic belongs to the counter type, this should be COUNTER.

  • The Rra:rra is used to specify how the data is stored. We can think of a rra as a table, each saving the statistical results of different interval. The role of RRA is to define how the updated data is recorded. For example, we generate a refreshed data every 5 minutes, so one hours is 12. Every day is 288 articles. Such a huge amount of data, it must not be saved. There must be a way to merge (consolidate) data, so this is what RRA is all about.

  • Pdp:primary Data Point. Normally each interval RRDtool receives a value, and RRDtool calculates another value (such as an average) after receiving the value from the script, which is the PDP; this value represents the meaning of "xxx/seconds". Note that this value is not necessarily equal to the value that RRDtool receives. Unless it's a gauge, look at the following example to find out.

  • CF:CF is the abbreviation of consolidation Function. That is, the merge (statistics) function. There are AVERAGE, Max, MIN, last four, respectively, the number of PDP to take the average, take the maximum value, take the minimum, take the current value of four types. The specific role waits until the update operation.

  • Cdp:consolidation Data Point. RRDtool uses multiple PDP to merge (calculate) a CDP. This is the result of performing the CF operation above. This value is the data that is stored in the RRA, which is used when plotting

Drawing ideas:

1. Establish the database:

2. Crawl Data traffic

3. Update RRDtool Database

4. Drawing graphics

Experiment begins: Learn from the 51 tutorials with Marco. Define a monitor MySQL traffic and draw graphics:

1. Define the database:

[[Email protected] ~] # rrdtool Create MYSQL.RRD--step 3 ds:mysqlselect:counter:5:0:u rra:average:0.5:1:28800 Rra:averag e:0.5:10:2880 rra:max:0.5:10:2880 rra:last:0.5:10:2880

Note: DS: Data Source: DST Type counter: Data received within 5 seconds of delay valid: Minimum value: Max

RRA: Merge data type: (average. Maximum value, minimum value): 0.5 for Unknow. If the probability of failure is greater than 0.5, no data is generated: 1 (represents a PDP unit rollup.) 5 = 5 PDP Unit Rollup average): 28800 here means one day algorithm example (one day 86400S/3/1 second value: 86400/3*10)

The current directory then generates the following: Mysql.rrd file:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/70/wKioL1SCtzHhB0gbAABurWOTUNY386.jpg "title=" Rrd1.jpg "alt=" Wkiol1sctzhhb0gbaaburwotuny386.jpg "/>

2. Define data collection:

(1) Define the pace of the concurrency of a mobile MySQL data (dead loop):

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/70/wKioL1SCt7PC5eYjAADP5FD9bgU710.jpg "title=" Rrd2.jpg "alt=" wkiol1sct7pc5eyjaadp5fd9bgu710.jpg "/> In the middle of the command:

select= ' MySQL--batch-e ' show global status like ' Com_select ' | awk '/com_select/{print '

Here the command is in shell mode. To view MySQL concurrency (the database password is empty):

Second: RRDtool update mysql.rrd N: $SELECT (update mysql.rrd database, n represents the current time. $SELECT gets the number of concurrency)

(2) Here for the data more obvious reality, in writing a dead loop footstep. Insert data in the middle (the database TestDB and table tb1 have been created earlier.) TB1 defines two fields for ID and name, respectively. The ID field takes care to make an auto-grow):

[[Email protected] ~] # vim insert.sh#!/bin/bash#for I in {1..200000}; Do mysql-e "INSERT into TESTDB.TB1 (name) VALUES (' stu$i ')" MYSQL-E "select * from Testdb.tb1" &>/dev/nul Ldone

Note: The step is constantly inserted into the data, and query, so the concurrency is high.

(3) Execute the script separately: Bash-x getselect.sh and Bash-x insert.sh (observe if there is an error, some words to check the script, the script can not be interrupted, open three windows to execute respectively. The update to this step of the data has been completed and the following is the drawing:

3. Draw the graph:

RRDtool fetch-r 3 mysql.rrd AVERAGE #查看是否手机到数据:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/72/wKiom1SCutHQJg4gAAE8AZ3O9-Q371.jpg "title=" Rrd3.jpg "alt=" Wkiom1scuthqjg4gaae8az3o9-q371.jpg "/>:

You can see that the data has been collected:-nan indicates no data: A numeric representation of the data received:

Then you can draw the graph: We start collecting data from the time we have the data. For example: 1417853451

Start Drawing:

[Email protected] rrd]# rrdtool graph mysql1.png-s 1417853451-t "MySQL select"-V "SELECTS/3" def:select3=mysql.rrd:my Sqlselect:average:step=3 line1:select3#ff0000: "Select"

497x174

[Email protected] rrd]#

Note:-S indicates the draw start time. The default is before 10s. You can also specify the current time by-N. -T represents the head of the picture:-V represents the name of the x-axis: DEF (method of Drawing graphics): Select3 variable =mysql.rrd:mysqlselect:average (the drawing type can also represent Max and last current values): step=3 (resolution, Represents a summary image per 3s phone) LINE1 (drawing type): select3#ff0000 (line color)

You can see that the current directory is generated below. Pictures of Myslq1.png. To pull the picture onto the Windows computer, the reality is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/54/70/wKioL1SCvbWS9ieVAAEAdEkPuc8739.jpg "title=" Rrd4.png "alt=" Wkiol1scvbws9ievaaeadekpuc8739.jpg "/>

The diagram has been completed, if the regular mobile phone data, you can use the SNMPD protocol mobile phone client data. Then generate and finally generate a graph with a simple web static Web page;

1. Build Library:

[[Email protected] ~] # rrdtool Create NGINX.RRD--step 3 ds:mysqlselect:counter:5:0:u rra:average:0.5:1:28800 Rra:averag e:0.5:10:2880 rra:max:0.5:10:2880 rra:last:0.5:10:2880

Extension: Usually we often want to draw some data like nginx concurrent Volume connection: We can write a script like this:

2, #!/bin/bash

#

While true; Do

Est= ' NETSTAT-ANP | grep EST | grep php-fpm | Wc-l '

RRDtool update nginx.rrd N: $EST

3. Draw the graph:

RRDtool graph nginx.png-s 1417853451-t "Nginx Select"-V "SELECTS/3" def:select3=nginx.rrd:mysqlselect:average:step=3 L ine1:select3#ff0000: "Select"

Here to monitor the concurrency has been completed, here I do not do test results, write this encounter problems of friends can communicate.


This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1587075

RRDtool Learning and Customizing script drawing graphics Memo

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.