[Rrdtool] Monitoring and automatic drawing, simple monitoring. 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 the rrd database shell script to regularly update the data shell script in rrd to regularly draw images (a 24-hour image is drawn here) to generate html and include the images. You can directly access the development initialization interface.
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
100 server traffic concurrency Monitoring Chart
Traffic trends within 24 hours
Concurrency trend within 24 hours
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; }