Skip to content

Commit e48992c

Browse files
committed
RRD custom time interval support
1 parent a45bf7e commit e48992c

File tree

10 files changed

+304
-159
lines changed

10 files changed

+304
-159
lines changed

bin/v_upd_sys_rrd

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# info: updating system rrd charts
3+
4+
#----------------------------------------------------------#
5+
# Variable&Function #
6+
#----------------------------------------------------------#
7+
8+
# Importing system enviroment as we run this script
9+
# mostly by cron wich do not read it by itself
10+
source /etc/profile.d/vesta.sh
11+
12+
13+
# Importing variables
14+
source $VESTA/conf/vars.conf
15+
source $V_CONF/vesta.conf
16+
source $V_FUNC/shared_func.sh
17+
18+
# Another workaround for cron enviroment
19+
PATH="$PATH:$V_BIN"
20+
export PATH
21+
22+
23+
#----------------------------------------------------------#
24+
# Action #
25+
#----------------------------------------------------------#
26+
27+
# Updateing system stats
28+
$V_BIN/v_upd_sys_rrd_la
29+
$V_BIN/v_upd_sys_rrd_net
30+
$V_BIN/v_upd_sys_rrd_mem
31+
$V_BIN/v_upd_sys_rrd_ssh
32+
33+
# Updating web stats
34+
if [ "$WEB_SYSTEM" = 'apache' ]; then
35+
$V_BIN/v_upd_sys_rrd_httpd
36+
fi
37+
38+
if [ "$PROXY_SYSTEM" = 'nginx' ]; then
39+
$V_BIN/v_upd_sys_rrd_nginx
40+
fi
41+
42+
# Updating ftp stats
43+
if [ ! -z "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
44+
$V_BIN/v_upd_sys_rrd_ftp
45+
fi
46+
47+
# Updating db stats
48+
if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
49+
for type in ${DB_SYSTEM//,/ }; do
50+
# Switching on db type
51+
case $type in
52+
mysql) $V_BIN/v_upd_sys_rrd_mysql ;;
53+
pgsql) $V_BIN/v_upd_sys_rrd_pgsql ;;
54+
esac
55+
done
56+
fi
57+
58+
59+
#----------------------------------------------------------#
60+
# Vesta #
61+
#----------------------------------------------------------#
62+
63+
# Logging
64+
log_event 'system' "$V_EVENT"
65+
66+
exit $OK

bin/v_upd_sys_rrd_ftp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# Variable&Function #
66
#----------------------------------------------------------#
77

8+
# Argument defenition
9+
rrd_start="${1--1d}"
10+
rrd_end="${2-now}"
11+
rrd_grid="${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}"
12+
813
# Importing variables
914
source $VESTA/conf/vars.conf
1015
source $V_CONF/vesta.conf
@@ -35,22 +40,25 @@ if [ ! -e "$V_RRD/ftp/ftp.rrd" ]; then
3540
fi
3641

3742
# Parsing data
38-
a=0
39-
a=$(ps aux |grep $FTP_SYSTEM |grep -v grep| grep -v nobody| grep -v root|wc -l)
43+
if [ -z "$1" ]; then
44+
a=0
45+
a=$(ps aux |grep $FTP_SYSTEM |grep -v grep| grep -v nobody|\
46+
grep -v root|wc -l)
4047

41-
# Updating rrd database
42-
rrdtool update $V_RRD/ftp/ftp.rrd N:$a
48+
# Updating rrd database
49+
rrdtool update $V_RRD/ftp/ftp.rrd N:$a
50+
fi
4351

44-
# Updating daily graph
52+
# Updating rrd graph
4553
rrdtool graph $V_RRD/ftp/ftp.png \
4654
--imgformat PNG \
4755
--height="120" \
4856
--width="440" \
49-
--start -1d \
50-
--end now \
57+
--start "$rrd_start" \
58+
--end "$rrd_end" \
5159
--title "$(echo $FTP_SYSTEM|tr '[a-z]' '[A-Z]') Usage" \
5260
--vertical-label "Connections" \
53-
--x-grid MINUTE:30:HOUR:1:HOUR:4:0:%H:%M\
61+
--x-grid "$rrd_grid" \
5462
-c "BACK#484439" \
5563
-c "SHADEA#484439" \
5664
-c "SHADEB#484439" \
@@ -65,14 +73,15 @@ rrdtool graph $V_RRD/ftp/ftp.png \
6573
LINE1:a#fefda0:"Users " \
6674
GPRINT:a:'LAST:Current\:''%8.0lf' \
6775
GPRINT:a:'MIN:Min\:''%8.0lf' \
68-
GPRINT:a:'MAX:Max\:''%8.0lf\j' > /dev/null
76+
GPRINT:a:'MAX:Max\:''%8.0lf\j' >/dev/null 2>/dev/null; result=$?
6977

7078

7179
#----------------------------------------------------------#
7280
# Vesta #
7381
#----------------------------------------------------------#
7482

75-
# No Logging
76-
#log_event 'system' "$V_EVENT"
83+
if [ "$result" -ne 0 ]; then
84+
exit $E_RRD_FAILED
85+
fi
7786

7887
exit $OK

bin/v_upd_sys_rrd_httpd

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# Variable&Function #
66
#----------------------------------------------------------#
77

8+
# Argument defenition
9+
rrd_start="${1--1d}"
10+
rrd_end="${2-now}"
11+
rrd_grid="${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}"
12+
813
# Importing variables
914
source $VESTA/conf/vars.conf
1015
source $V_CONF/vesta.conf
@@ -37,29 +42,31 @@ if [ ! -e "$V_RRD/web/httpd.rrd" ]; then
3742
fi
3843

3944
# Parsing data
40-
web_port=$(get_config_value '$WEB_PORT')
41-
server_status=$(wget -qO- http://localhost:$web_port/server-status |\
42-
grep 'currently being processed'| \
43-
cut -f 2 -d '>' |\
44-
sed 's/requests currently being processed, //' | \
45-
cut -f 1,2 -d ' ')
46-
active=$(echo "$server_status"|cut -f 1 -d ' ')
47-
idle=$(echo "$server_status"|cut -f 1 -d ' ')
48-
a=$((active + idle))
45+
if [ -z "$1" ]; then
46+
web_port=$(get_config_value '$WEB_PORT')
47+
server_status=$(wget -qO- http://localhost:$web_port/server-status |\
48+
grep 'currently being processed'| \
49+
cut -f 2 -d '>' |\
50+
sed 's/requests currently being processed, //' | \
51+
cut -f 1,2 -d ' ')
52+
active=$(echo "$server_status"|cut -f 1 -d ' ')
53+
idle=$(echo "$server_status"|cut -f 1 -d ' ')
54+
a=$((active + idle))
4955

50-
# Updating rrd database
51-
rrdtool update $V_RRD/web/httpd.rrd N:$a
56+
# Updating rrd database
57+
rrdtool update $V_RRD/web/httpd.rrd N:$a
58+
fi
5259

53-
# Updating daily graph
60+
# Updating rrd graph
5461
rrdtool graph $V_RRD/web/httpd.png \
5562
--imgformat PNG \
5663
--height="120" \
5764
--width="440" \
58-
--start -1d \
59-
--end now \
65+
--start "$rrd_start" \
66+
--end "$rrd_end" \
6067
--title "HTTPD Usage" \
6168
--vertical-label "Connections" \
62-
--x-grid MINUTE:30:HOUR:1:HOUR:4:0:%H:%M\
69+
--x-grid "$rrd_grid" \
6370
-c "BACK#484439" \
6471
-c "SHADEA#484439" \
6572
-c "SHADEB#484439" \
@@ -74,14 +81,15 @@ rrdtool graph $V_RRD/web/httpd.png \
7481
LINE1:a#fefda0:"Connections " \
7582
GPRINT:a:'LAST:Current\:''%8.0lf' \
7683
GPRINT:a:'MIN:Min\:''%8.0lf' \
77-
GPRINT:a:'MAX:Max\:''%8.0lf\j' > /dev/null
84+
GPRINT:a:'MAX:Max\:''%8.0lf\j' >/dev/null 2>/dev/null; result=$?
7885

7986

8087
#----------------------------------------------------------#
8188
# Vesta #
8289
#----------------------------------------------------------#
8390

84-
# No Logging
85-
#log_event 'system' "$V_EVENT"
91+
if [ "$result" -ne 0 ]; then
92+
exit $E_RRD_FAILED
93+
fi
8694

8795
exit $OK

bin/v_upd_sys_rrd_la

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# Variable&Function #
66
#----------------------------------------------------------#
77

8+
# Argument defenition
9+
rrd_start="${1--1d}"
10+
rrd_end="${2-now}"
11+
rrd_grid="${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}"
12+
813
# Importing variables
914
source $VESTA/conf/vars.conf
1015

@@ -35,23 +40,25 @@ if [ ! -e "$V_RRD/la/la.rrd" ]; then
3540
fi
3641

3742
# Parsing data
38-
loadavg=$(cat /proc/loadavg )
39-
la=$(echo "$loadavg"|cut -f 2 -d ' ')
40-
pr=$(echo "$loadavg"|cut -f 4 -d ' '|cut -f 2 -d /)
43+
if [ -z "$1" ]; then
44+
loadavg=$(cat /proc/loadavg )
45+
la=$(echo "$loadavg"|cut -f 2 -d ' ')
46+
pr=$(echo "$loadavg"|cut -f 4 -d ' '|cut -f 2 -d /)
4147

42-
# Updating rrd database
43-
rrdtool update $V_RRD/la/la.rrd N:${la//./}:$pr
48+
# Updating rrd database
49+
rrdtool update $V_RRD/la/la.rrd N:${la//./}:$pr
50+
fi
4451

45-
# Updating daily graph
52+
# Updating graph
4653
rrdtool graph $V_RRD/la/la.png \
4754
--imgformat PNG \
4855
--height="120" \
4956
--width="440" \
50-
--start -1d \
51-
--end now \
57+
--start "$rrd_start" \
58+
--end "$rrd_end" \
5259
--title "Load Average" \
5360
--vertical-label "Points" \
54-
--x-grid MINUTE:30:HOUR:1:HOUR:4:0:%H:%M\
61+
--x-grid "$rrd_grid" \
5562
-c "BACK#484439" \
5663
-c "SHADEA#484439" \
5764
-c "SHADEB#484439" \
@@ -71,14 +78,15 @@ rrdtool graph $V_RRD/la/la.png \
7178
LINE1:pr#1c74cd:"Procs # " \
7279
GPRINT:pr:'LAST:Current\:''%8.0lf' \
7380
GPRINT:pr:'MIN:Min\:''%8.0lf' \
74-
GPRINT:pr:'MAX:Max\:''%8.0lf\j' >/dev/null
81+
GPRINT:pr:'MAX:Max\:''%8.0lf\j' >/dev/null 2>/dev/null; result=$?
7582

7683

7784
#----------------------------------------------------------#
7885
# Vesta #
7986
#----------------------------------------------------------#
8087

81-
# No Logging
82-
#log_event 'system' "$V_EVENT"
88+
if [ "$result" -ne 0 ]; then
89+
exit $E_RRD_FAILED
90+
fi
8391

8492
exit $OK

bin/v_upd_sys_rrd_mem

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# Variable&Function #
66
#----------------------------------------------------------#
77

8+
# Argument defenition
9+
rrd_start="${1--1d}"
10+
rrd_end="${2-now}"
11+
rrd_grid="${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}"
12+
813
# Importing variables
914
source $VESTA/conf/vars.conf
1015

@@ -35,23 +40,25 @@ if [ ! -e "$V_RRD/mem/mem.rrd" ]; then
3540
fi
3641

3742
# Parsing data
38-
mem=$(free -m)
39-
ram=$(echo "$mem" |awk '{print $3}'|head -n2 |tail -n1)
40-
swap=$(echo "$mem" |awk '{print $3}'|tail -n1)
43+
if [ -z "$1" ]; then
44+
mem=$(free -m)
45+
ram=$(echo "$mem" |awk '{print $3}'|head -n2 |tail -n1)
46+
swap=$(echo "$mem" |awk '{print $3}'|tail -n1)
4147

42-
# Updating rrd
43-
rrdtool update $V_RRD/mem/mem.rrd N:$ram:$swap
48+
# Updating rrd
49+
rrdtool update $V_RRD/mem/mem.rrd N:$ram:$swap
50+
fi
4451

45-
# Updating daily graph
52+
# Updating rrd graph
4653
rrdtool graph $V_RRD/mem/mem.png \
4754
--imgformat PNG \
4855
--height="120" \
4956
--width="440" \
50-
--start -1d \
51-
--end now \
57+
--start "$rrd_start" \
58+
--end "$rrd_end" \
5259
--title "Memory Usage" \
5360
--vertical-label "Mbytes" \
54-
--x-grid MINUTE:30:HOUR:1:HOUR:4:0:%H:%M\
61+
--x-grid "$rrd_grid" \
5562
-c "BACK#484439" \
5663
-c "SHADEA#484439" \
5764
-c "SHADEB#484439" \
@@ -71,14 +78,15 @@ rrdtool graph $V_RRD/mem/mem.png \
7178
LINE1:swap#f57900:"SWAP" \
7279
GPRINT:swap:'LAST:Current\:''%8.0lf' \
7380
GPRINT:swap:'MIN:Min\:''%8.0lf' \
74-
GPRINT:swap:'MAX:Max\:''%8.0lf\j' > /dev/null
81+
GPRINT:swap:'MAX:Max\:''%8.0lf\j' >/dev/null 2> /dev/null; result=$?
7582

7683

7784
#----------------------------------------------------------#
7885
# Vesta #
7986
#----------------------------------------------------------#
8087

81-
# No Logging
82-
#log_event 'system' "$V_EVENT"
88+
if [ "$result" -ne 0 ]; then
89+
exit $E_RRD_FAILED
90+
fi
8391

8492
exit $OK

0 commit comments

Comments
 (0)