Now, the website server has used snmp for monitoring and has monitored the CPU, memory, and traffic. However, I think we still need to monitor the PV and IP of the website, in this way, you can quickly find out if the server load increases because of the increase in website traffic. Rrdtool has been a beginner in the past few days. This tool can store data and draw pictures, which is very convenient.
The following figure shows the PVs and ip addresses of the last day.
1. install rrdtoolcentos: yum install rrdtool
Ubuntu: sudo apt-get install rrdtool
2. Create an rrdtool Database
Rrdtool create/var/www/test. rrd \
-S 300 \
DS: pv: GAUGE: 600: U \
DS: ip: GAUGE: 600: U \
RRA: AVERAGE: 0.5: 1: 288
Create a test. rrd data file. The parameters are described as follows:
-S 300 300 seconds to store data once
DS: pv: GAUGE: 600: U
DS: ip: GAUGE: 600: U: specify two data sources DS. The fields are pv and ip respectively.
RRA: AVERAGE: 0.5: 1: 288 specifies RRA, which is equivalent to a data table that stores data for one day. 3. Create an update script
#! /Bin/bash
Becur = 'date-d "5 minute ago" + % H % M % s'
List = 'tac/var/log/apache2/access. log | awk-v a = "$ becur"-F ['':] '{t = $5 $6 $7; if (t> = a) {print ;} else {exit ;}' | egrep-v "\. (gif | jpg | jpeg | png | css | js )"'
# Obtain PV within five minutes
Pv = 'echo "$ list" | wc-l'
# Obtain the IP address within five minutes
Ip = 'echo "$ list" | awk '{print $1}' | sort | uniq | wc-l'
# Update the database every five minutes
Rrdtool update/var/www/test. rrd N :$ {pv }:: {ip}
# Update images every five minutes
Rrdtool graph/var/www/1-pv.png \
-T "PV and IP statistics in an hour "\
-- Start now-3600 \
-- Watermark "'date '"\
-- No-gridfit \
-- Slope-mode \
-L 0 \
-Y 1000:5 \
-X 0 \
DEF: mypv =/var/www/test. rrd: pv: AVERAGE \
DEF: myip =/var/www/test. rrd: ip: AVERAGE \
AREA: mypv # 9F35FF: "PV Num "\
AREA: myip #00DB00: "IP Num"
Add the script to the scheduled task and execute it every five minutes.
This is a script that contains data updates and image generation. The parameters are described as follows:
-T "PV and IP statistics in an hour" specifies the chart title
-- Start now-3600: Get data for the last hour
-L 0 y axis starts from 0
-Y: 5 defines that the y axis separator is, and 5 entries display a scale.
-X 0 displays the Y axis as the original value
Rrdtool Tutorials: http://oss.oetiker.ch/rrdtool/