RRDtool is a way to store data, is a powerful drawing engine, so how to use RRDtool on Linux? The following small series will introduce you to the way Linux uses RRDtool, let's learn together.
I. Introduction
RRDtool refers to the Round Robin Database tool, the ring database. Functionally, RRDtool can be used for data storage + data presentation. The well-known network traffic mapping software MRTG and the cluster monitoring system Ganglia use RRDtool.
In terms of data storage, RRDtool uses the "Round Robin" mode to store data. The so-called "Round Robin" is a way to store data, using a fixed amount of space to store data, and a pointer to the location of the latest data. We can think of the database space used to store data as a circle with a lot of scales, and the location of these scales represents where the data is stored. The so-called pointer can be thought of as a line pointing from the center of the circle to these scales. The pointer moves automatically as the data is read and written. It should be noted that this circle has no start and end points, so the pointer can move all the time without worrying about the problem of not being able to continue writing after reaching the end point. After a while, when all the space is full of data, it is stored from the beginning. Thus the size of the entire storage space is a fixed value. The suffix name of the database file used by RRDtool is “.rrd”.
In terms of data display, RRDtool can be seen as a powerful drawing engine. The following picture is an rendering of the official website. We have a general understanding of the drawing capabilities of RRDtool.
Second, the basic syntax
using RRDtool divided into three parts, building a database, update data, the drawing (particularly using the shell command). Therefore, we also introduce the basic grammar in the above three parts.
1, build the library
For the sake of clarity, here will be the library command to write the segment form, the actual application should be written into a string.
rrdtool create cpu.rrd # database name
--start $ (date -d & lsquo; 1 days ago & rsquo; +% s) # start time
--step 15 # update data interval
DS: cpu_user: GAUGE: 120: 0: NaN # DS: cpu_user, corresponding to the variable name; the latter is DST: GAUGE, corresponding to the data type; 120 is behind heartbeat, Is the maximum interval without data; the latter two NaN are the minimum and maximum limits respectively.
DS:cpu_system:GAUGE:120:0:NaN
DS:cpu_wio:GAUGE:120:0:NaN
DS:cpu_idle:GAUGE:120:0: NaN
RRA:AVERAGE:0.5:1:244 # RRA is the form of data storage, data table
RRA:AVERAGE:0.5:24:244 # CF merge statistics have average, max, Min, last four
RRA:AVERAGE:0.5:168:244 # 0.5 is xff, indicating that the missing data amount is greater than 0.5, the data is empty.
RRA:AVERAGE:0.5:672:244 # PDP, a calculated data point, such as the average value, etc.
RRA:AVERAGE:0.5:5760:374 # CDP, use multiple PDP is merged into a CDP. CDP is the value that is actually stored in RRA. It is also the value used in drawing. How many PDPs are combined into one CDP, such as 1, 24, 168, 672, etc.
The purpose of this code is to create a rrd database cpu.rrd, save cpu related information, update the data every 15 seconds.
Second, update
Update is relatively simple, is to periodically write data to the database (ie.rrd file). Each time a command is written, it is similar to the following instruction.
rrdtool updatev /var/lib/monitor/rrds/server/cpu.rrd 1382646278: 0.733211: 0.433261: 1.516414: 97.317114
# /var /lib /monitor /rrds /server /cpu .rrd is the database file
# 1382646278 is the timestamp
# 0.733211:0.433261:1.516414:97.317114 is the specific value written, respectively, refers to cpu_user, cpu_system, cpu_wio, cpu_idle.
In actual use, you should write a program to periodically obtain cpu utilization, and execute the above command to write data to the database.
Third, drawing
Similar to the time of building a library, for the sake of clarity, the drawing commands are written in the form of segments, which should be written in a series.
/usr /bin /rrdtool graph /home/xx/cpu.png
--start & lsquo; -3600 & rsquo; --end N //past hour
--width 385 --height 190 //image size
--title & lsquo; CPU usage in the last hour & rsquo; 100 --lower limit-0 //Title --upper-limit and upper Lower Limit
--vertical-label Percentage--rigid
DEF:‘cpu_user’=‘/var/lib/monitor/rrds/server/cpu.rrd’:‘cpu_user&rsquo ;: AVERAGE # obtain variable cpu_user
AREA: & lsquo; cpu_user & rsquo; # FF0000: & lsquo; user & rsquo; //graphical form, including AREA, STACK, LINE other
VDEF: cpu_user_last = cpu_user , LAST //variable definition, takes a specific value
VDEF: cpu_user_avg = cpu_user, AVERAGE
GPRINT: & lsquo; cpu_user_last & rsquo;: & lsquo; Now \\:% 5.1lf% s & rsquo; //in Print the value in the image
GPRINT:‘cpu_user_avg’:‘ Avg\\:%5.1lf%s\\j’ DEF:‘cpu_system’=‘/var/lib/mon itor /rrds /server /cpu.rrd & rsquo;: & lsquo; cpu_system & rsquo;: AVERAGE STACK: & lsquo; cpu_system & rsquo; # 33cc33: & lsquo; system & rsquo; VDEF: cpu_system_last = cpu_system, LAST VDEF: cpu_system_avg = cpu_system, AVERAGE GPRINT: & lsquo; cpu_system_last & rsquo ;: & lsquo; Now \\:% 5.1lf% s & rsquo; GPRINT: & lsquo; cpu_system_avg & rsquo;: & lsquo; Avg \\:% 5.1lf% s \\ j & rsquo; DEF: & lsquo; cpu_wio & rsquo; = & lsquo; /var /lib /monitor /rrds /server/cpu.rrd’:‘cpu_wio’:AVERAGE STACK: & lsquo; cpu_wio & rsquo; # 1C86EE: & lsquo; wait & rsquo; VDEF: cpu_wio_last = cpu_wio, LAST VDEF: cpu_wio_avg = cpu_wio, AVERAGE GPRINT: & lsquo; cpu_wio_last & rsquo;: & lsquo ; Now \\:% 5.1lf% s & rsquo; GPRINT: & lsquo; cpu_wio_avg & rsquo;: & lsquo; Avg \\:% 5.1lf% s \\ j & rsquo; DEF: & lsquo; cpu_idle & rsquo; = & lsquo; /var /lib /monitor /rrds /server /cpu.rrd & rsquo;: & lsquo; cpu_idle & rsquo;: AVERAGE STACK: & lsquo; cpu_idle & rsquo; # e2e2f2: & lsquo; idle & rsquo; VDEF: cpu_idle_last = cpu_idle, LAST VDEF: cpu_idle_avg = cpu_idle, AVERAGE GPRINT: & lsquo ;cpu_idle_last’:‘ Now\\:%5.1lf%s’ GPRINT:‘cpu_idle_avg’:‘ Avg\\:%5.1lf%s\\j’
The images are as follows. I deliberately stopped updating the data for a while, and the pictures obtained by the drawing were also monitored and showed no data during the corresponding time period.
Linux is above RRDtool learning methods introduced, because there are a lot of tools such as MRTG RRDtool can call the drawing, so knowledge of RRDtool or a certain necessary.
Fluentd as a log collection system, its users are still very large, but the steps t
After installing Linux system with vps, I found that there are not enough available partitions. This
curl is an open source file transfer tool that can be used in Linux systems. If you
Linux users generally use the active mode when using the vsftpd server, but the vsf
What are the common commands for Linux rookie?
How to turn off the scp and sftp commands in Linux
Steps to Add Static Routes to Linux
Linux how to use the setfacl command to create a permission file
How to use rmdir command guide in Linux
How to configure a firewall for a Linux system using the iptables command
Linux system how to install and configure ClusterShell tool
How to view the version of MariaDB server on Linux system
What is optimized for Linux kernel 4.2?
How to use the command line to change the date and time of the Linux system
How to open doc file Win10 Win10 open doc file garbled solution
Win10 mobile phone preview version 10149 update repair content summary
Optimize the iPhone to make it faster.
Win10 preview version 10075 updated what content
Completely solve the problem of Internet access between XPs.
Use the Notepad command - Quickly delete the specified Windows 7 registry key
How does Win7 display the file suffix name
Forgot your password, how do I unlock BitLocker?
Where is the Windows kernel version number?
How to clear the plain text display function of the Win10 login password input box?