Using RRDtool for Vmstat output drawing in Linux

Source: Internet
Author: User
Tags rrd rrdtool

1, view the output of Vmstat

[Root@361way ~]# Vmstat 1 2
procs-----------Memory-------------Swap-------io------System-------CPU-----
R b swpd free buff cache si so bi bo in CS us sy ID WA St
0 0 0 1479452 420588 5600548 0 0 0 3 0 5 0 0 100 0-0
0 0 0 1479444 420588 5600548 0 0 0 0 40 37 0 0 100 0-0


2, for the Vmstat output results to build a table

RRDtool Create VMSTAT.RRD--step 1\
Ds:r:gauge:5:u:u\
Ds:b:gauge:5:u:u\
Ds:swpd:gauge:5:u:u\
Ds:free:gauge:5:u:u\
Ds:buff:gauge:5:u:u\
Ds:cache:gauge:5:u:u\
Ds:si:gauge:5:u:u\
Ds:so:gauge:5:u:u\
Ds:bi:gauge:5:u:u\
Ds:bo:gauge:5:u:u\
Ds:in:gauge:5:u:u\
Ds:cs:gauge:5:u:u\
Ds:us:gauge:5:u:u\
Ds:sy:gauge:5:u:u\
Ds:id:gauge:5:u:u\
Ds:wa:gauge:5:u:u\
Ds:st:gauge:5:u:u\
rra:average:0.5:1:100000

The 5 in Ds:r:gauge:5:u:u indicates that the maximum heartbeat time seconds are updated two times. The first u represents the minimum value, the second U represents the maximum, and U (ulimit) indicates that the value is not limited.

3, the output of Vmstat will be stored in the Vmstat.rrd file

Vmstat 1 600 | Awk-v time= ' Date +%s '/^. [0-9]/{n++ print rrdtool update vmstat.rrd ' time+n ': ' $ ': ' $ ': "$": "$": "$": "$": "$": "$": "$ 0 ":" $11 ":" $ ":" $ ":" $14 ":" $ ":" $16 ":" $17} ' >vmstat.output
Bash <./vmstat.output
Collects data from the last 10 minutes and guides it to the VMSTAT.RRD library file.

4, using RRDtool graph map

RRDtool with the chart parameters, you can use RRDtool graph to draw the data just entered

#图1
RRDtool Graph physical_consumed.gif\
--title "physical CPU consumed" \
--vertical-label "CPUs" \
--height 300\
--start 1422606034\
--end 1422606333\
Def:st=vmstat.rrd:st:average line2:st#00ff00: "Physical Consumed"
#图2
RRDtool Graph cpu_util.gif\
--rigid--lower-limit 0--upper-limit 100\
--title "CPU Util" \
--vertical-label "Percent stacked" \
--start 1422606034\
--end 1422606333\
--height 300\
Def:us=vmstat.rrd:us:average area:us#00ff00: "User" \
Def:sy=vmstat.rrd:sy:average stack:sy#0000ff: "System" \
Def:wa=vmstat.rrd:wa:average stack:wa#ff0000: "Wait" \
Def:id=vmstat.rrd:id:average stack:id#ffffff: "Idle"
Note:

1, on the required start and end time, can be obtained from the value of the fourth column in the Vmstat.output file;

2, Lower-limit, and Upper-limit specify the upper and lower limits for the ordinate of the cpu_util chart.

The resulting effect diagram is as follows:

5, the complete script is as follows

#!/bin/bash
RRDtool Create VMSTAT.RRD--step 1\
Ds:r:gauge:5:u:u\
Ds:b:gauge:5:u:u\
Ds:swpd:gauge:5:u:u\
Ds:free:gauge:5:u:u\
Ds:buff:gauge:5:u:u\
Ds:cache:gauge:5:u:u\
Ds:si:gauge:5:u:u\
Ds:so:gauge:5:u:u\
Ds:bi:gauge:5:u:u\
Ds:bo:gauge:5:u:u\
Ds:in:gauge:5:u:u\
Ds:cs:gauge:5:u:u\
Ds:us:gauge:5:u:u\
Ds:sy:gauge:5:u:u\
Ds:id:gauge:5:u:u\
Ds:wa:gauge:5:u:u\
Ds:st:gauge:5:u:u\
rra:average:0.5:1:100000
$TIME = ' Date +%s '
Vmstat 1 600 | Awk-v time= $TIME '/^. [0-9]/{n++ print rrdtool update vmstat.rrd ' time+n ': ' $ ': ' $ ': "$": "$": "$": "$": "$": "$": "$ 0 ":" $11 ":" $ ":" $ ":" $14 ":" $ ":" $16 ":" $17} ' >vmstat.output
$ENDTIME = ' Date +%s '
Bash <./vmstat.output
RRDtool Graph physical_consumed.gif\
--title "physical CPU consumed" \
--vertical-label "CPUs" \
--height 300\
--start $TIME \
--end $ENDTIME \
Def:st=vmstat.rrd:st:average line2:st#00ff00: "Physical Consumed"
RRDtool Graph cpu_util.gif\
--rigid--lower-limit 0--upper-limit 100\
--title "CPU Util" \
--vertical-label "Percent stacked" \
--start $TIME \
--end $ENDTIME \
--height 300\
Def:us=vmstat.rrd:us:average area:us#00ff00: "User" \
Def:sy=vmstat.rrd:sy:average stack:sy#0000ff: "System" \
Def:wa=vmstat.rrd:wa:average stack:wa#ff0000: "Wait" \
Def:id=vmstat.rrd:id:average stack:id#ffffff: "Idle"

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.