Now want to monitor the traffic and concurrency of the service, but not so much time to write the system, the other operation and maintenance system is not familiar with, so the existing RRDtool shell made a simple monitoring interface, temporary use, but also a small experiment. RRDtool is also just contact, a little exercise
Process
The approximate process is this (CENTOS6 operating system)
- Initializing the RRD database
- Shell script updates data in RRD at regular intervals
- Shell script timed drawing (here is a 24-hour drawing) to generate a picture
- HTML, to include the picture inside. Interface provides direct access to
Development initialization
Mainly 2 functions, 24-hour flow chart, 24-hour concurrent graph (5-minute sampling, not all real-time monitoring)
RRDtool Create eth1. RRD --step300DS: eth1_in: COUNTER:: 0: U DS: Eth1_out: COUNTER:: 0: U RRA: AVERAGE: 0. 5: 1: RRA: AVERAGE: 0. 5: 4: RRA: AVERAGE: 0. 5:: RRA: AVERAGE: 0. 5: 288: 730 RRA: MAX: 0. 5: 1: RRA: MAX: 0. 5: 4: RRA: MAX: 0. 5:: RRA: MAX: 0. 5: 288: 730RRDtool Create Curnum. RRD --step300DS: Num: GAUGE:: 0: U RRA: AVERAGE: 0. 5: 1: RRA: AVERAGE: 0. 5: 4: RRA: AVERAGE: 0. 5:: RRA: AVERAGE: 0. 5: 288: 730 RRA: MAX: 0. 5: 1: RRA: MAX: 0. 5: 4: RRA: MAX: 0. 5:: RRA: MAX: 0. 5: 288: 730
Update data
Update the script and draw, if cron,5 minutes
*/5 * * * * /bin/sh /home/erya/run/monitor/rrd_update.sh >/dev/null 2>&1
[[email protected] moniter]# cat Rrd_update.sh#!/bin/bash#orangleliu#centos Get the size of a time-out packet for a network cardEth_name="Eth1"inch=$ (Cat/proc/net/dev|grep eth1|cut- D ': ' - F 2|awk' {print '} ') 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
Draw script, every 5 minutes (cron, or append in the last part of the update script
*/5 * * * * /bin/sh /home/erya/run/monitor/rrd_graph.sh >/dev/null 2>&1
#!/bin/bash#5分钟画图一次,给页面访问cd /home/erya/run/monitor/usr/bin/rrdtool graph net.png --start -86400"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"100 server concurrency number 24 hours" DEF:value1=curnum.rrd:num:AVERAGE AREA:value1#00ff00:num
Then I wrote an HTML, two images included, configured in Nginx (just a few location), you can directly from the browser access.
Also, the super-simple way to monitor.
Interface
[email protected] moniter]# cat monitor.html<html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><tilte>100 server traffic Concurrency monitor diagram</title></head><body> <h3>Traffic trends in 24 hours</h3> <img src="Http://xxx/rrd/net.png" /> <h3>Concurrency trend within 24 hours</h3> <img src="Http://xxx/rrd/curnum.png" /></body></html>
Nginx Configuration Fragment
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, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/46739853 author Orangleliu Use Attribution-NonCommercial-share agreements in the same way
Copyright NOTICE: This article is Orangleliu (http://blog.csdn.net/orangleliu/) original article, the article reproduced please declare.
[RRDtool] Monitoring and automatic drawing, simple monitoring. MD