[Rrdtool] Monitoring and automatic drawing, simple monitoring. md, rrdtool. md

Source: Internet
Author: User
Tags rrd rrdtool

[Rrdtool] Monitoring and automatic drawing, simple monitoring. md, rrdtool. md

Now I want to monitor the traffic and concurrency of the service, but I don't have much time to write the system. Other O & M systems are unfamiliar, therefore, the existing rrdtool shell is used for a simple monitoring interface. Temporary use is also a small experiment. Rrdtool is just getting started. It's a small exercise.

Process

The general process is as follows (centos6 operating system)

  • Initialize rrd Database
  • Regularly update data in rrd using shell scripts
  • Shell script regular drawing (a 24-hour image is drawn here) to generate an image
  • Html to include the image. Interface can be accessed directly
Development Initialization

There are two main functions: 24-hour traffic diagram and 24-hour concurrency diagram (5-minute sampling, not all real-time monitoring)

rrdtool create eth1.rrd --step 300 \DS:eth1_in:COUNTER:600:0:U \DS:eth1_out:COUNTER:600:0:U \RRA:AVERAGE:0.5:1:600 \RRA:AVERAGE:0.5:4:600 \RRA:AVERAGE:0.5:24:600 \RRA:AVERAGE:0.5:288:730 \RRA:MAX:0.5:1:600 \RRA:MAX:0.5:4:600 \RRA:MAX:0.5:24:600 \RRA:MAX:0.5:288:730rrdtool create curnum.rrd --step 300 \DS:num:GAUGE:600:0:U \RRA:AVERAGE:0.5:1:600 \RRA:AVERAGE:0.5:4:600 \RRA:AVERAGE:0.5:24:600 \RRA:AVERAGE:0.5:288:730 \RRA:MAX:0.5:1:600 \RRA:MAX:0.5:4:600 \RRA:MAX:0.5:24:600 \RRA:MAX:0.5:288:730
Update Data

Update the script and draw a picture. If cron is used once every 5 minutes
*/5 * * * * /bin/sh /home/erya/run/monitor/rrd_update.sh >/dev/null 2>&1

[Root @ localhost moniter] # cat rrd_update.sh #! /Bin/bash # orangleliu # centos obtains the size of the packet sent and received by a network adapter at a certain time. eth_name = "eth1" in =$ (cat/proc/net/dev | grep eth1 | cut-d ': '-f 2 | awk' {print $1}') out = $ (cat/proc/net/dev | grep eth1 | cut-d ': '-f 2 | awk' {print $9}') curnum = $ (netstat-nat | grep ESTABLISHED | wc-l) echo "$ eth_name int is $ {in}" echo "$ eth_name out is $ {out}" echo "curnum is $ {curnum}" # udpate rrdrrd_dir =/home/erya/ run/monitor/usr/bin/rrdtool updatev $ {rrd_dir}/eth1.rrd N: $ {in }:: {out}/usr/bin/rrdtool updatev $ {rrd_dir}/curnum. rrd N :$ {curnum}
Timed drawing

Drawing script, once every 5 minutes (cron, or append to the last part of the update script
*/5 * * * * /bin/sh /home/erya/run/monitor/rrd_graph.sh >/dev/null 2>&1

#! /Bin/bash # Drawing once every 5 minutes, access the page cd/home/erya/run/monitor/usr/bin/rrdtool graph net.png \ -- start-86400 -- end now \ -- title "100 server net flow 1 day "\ DEF: value1 = eth1.rrd: eth1_in: AVERAGE \ DEF: value2 = eth1.rrd: eth2_out: AVERAGE \ AREA: value1 #00ff00: in \ LINE2: value2 # ff0000: out: STACK/usr/bin/rrdtool graph curnum.png \ -- start-86400 -- end now \ -- title "100 server concurrency number 24 hours" \ DEF: value1 = curnum. rrd: num: AVERAGE \ AREA: value1 #00ff00: num

Then I wrote an html file, included two images, and configured them into nginx (several locations), so that they can be accessed directly from the browser.
This is also a simple monitoring method.

Interface
Root @ localhost moniter] # cat monitor.html 

Nginx configuration snippets

    location ^~/rrd/net.png {        alias /home/erya/run/monitor/net.png;    }    location ^~/rrd/curnum.png {        alias /home/erya/run/monitor/curnum.png;    }    location ^~/rrd/monitor.html {        alias /home/erya/run/monitor/monitor.html;    }

Statement:
This article is from the "orangleliu notebook" blog. You must retain this source for reprinting at http://blog.csdn.net/orangleliu/article/details/46739853zuorangleliu using signatures-non-commercial use-

Copyright: This article is orangleliu (http://blog.csdn.net/orangleliu/) Original article, reprinted please declare.

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.