Skip to content

Commit 69cf021

Browse files
committed
debian/ubuntu rrd for apache
1 parent 2737f52 commit 69cf021

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

bin/v-update-sys-rrd-apache2

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
# info: update apach2 rrd
3+
# options: PERIOD
4+
#
5+
# The function is for updating apache rrd database and graphic.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
period=${1-daily}
14+
15+
# Includes
16+
source $VESTA/conf/vesta.conf
17+
source $VESTA/func/main.sh
18+
19+
20+
#----------------------------------------------------------#
21+
# Action #
22+
#----------------------------------------------------------#
23+
24+
# Switching on time period
25+
case $period in
26+
daily) start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
27+
weekly) start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
28+
monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
29+
yearly) start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
30+
*) exit $E_RRD ;;
31+
esac
32+
33+
34+
# Checking directory
35+
if [ ! -d "$RRD/web" ]; then
36+
mkdir $RRD/web
37+
fi
38+
39+
# Checking database
40+
if [ ! -e "$RRD/web/apache2.rrd" ]; then
41+
# Adding database
42+
rrdtool create $RRD/web/apache2.rrd --step $RRD_STEP \
43+
DS:A:GAUGE:600:U:U \
44+
RRA:AVERAGE:0.5:1:600 \
45+
RRA:AVERAGE:0.5:6:700 \
46+
RRA:AVERAGE:0.5:24:775 \
47+
RRA:AVERAGE:0.5:288:797 \
48+
RRA:MAX:0.5:1:600 \
49+
RRA:MAX:0.5:6:700 \
50+
RRA:MAX:0.5:24:775 \
51+
RRA:MAX:0.5:288:797
52+
fi
53+
54+
# Parsing data
55+
if [ "$period" = 'daily' ]; then
56+
server_status=$(wget -qO- http://localhost:8081/server-status |\
57+
grep 'currently being processed'| \
58+
cut -f 2 -d '>' |\
59+
sed 's/requests currently being processed, //' | \
60+
cut -f 1,2 -d ' ')
61+
active=$(echo "$server_status"|cut -f 1 -d ' ')
62+
idle=$(echo "$server_status"|cut -f 1 -d ' ')
63+
a=$((active + idle))
64+
65+
# Updating rrd database
66+
rrdtool update $RRD/web/apache2.rrd N:$a
67+
fi
68+
69+
# Updating rrd graph
70+
rrdtool graph $RRD/web/$period-apache2.png \
71+
--imgformat PNG \
72+
--height="120" \
73+
--width="440" \
74+
--start "$start" \
75+
--end "$end" \
76+
--vertical-label "Connections" \
77+
--x-grid "$grid" \
78+
-c "BACK#7a766d" \
79+
-c "SHADEA#7a766d" \
80+
-c "SHADEB#7a766d" \
81+
-c "FONT#FFFFFF" \
82+
-c "CANVAS#302c2d" \
83+
-c "GRID#666666" \
84+
-c "MGRID#AAAAAA" \
85+
-c "FRAME#302c2d" \
86+
-c "ARROW#FFFFFF" \
87+
DEF:a=$RRD/web/apache2.rrd:A:AVERAGE \
88+
COMMENT:'\r' \
89+
LINE1:a#fefda0:"Connections " \
90+
GPRINT:a:'LAST:Current\:''%8.0lf' \
91+
GPRINT:a:'MIN:Min\:''%8.0lf' \
92+
GPRINT:a:'MAX:Max\:''%8.0lf\j' &>/dev/null; result=$?
93+
94+
95+
#----------------------------------------------------------#
96+
# Vesta #
97+
#----------------------------------------------------------#
98+
99+
if [ "$result" -ne 0 ]; then
100+
exit $E_RRD
101+
fi
102+
103+
exit

0 commit comments

Comments
 (0)