Bläddra i källkod

time period support for rrd

Serghey Rodin 14 år sedan
förälder
incheckning
0a0dc0a638

+ 12 - 9
bin/v_upd_sys_rrd

@@ -19,29 +19,32 @@ source $V_FUNC/shared.func
 PATH="$PATH:$V_BIN"
 export PATH
 
+# Argument defenition
+period=$1
+
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
 # Updateing system stats
-$V_BIN/v_upd_sys_rrd_la
-$V_BIN/v_upd_sys_rrd_net
-$V_BIN/v_upd_sys_rrd_mem
-$V_BIN/v_upd_sys_rrd_ssh
+$V_BIN/v_upd_sys_rrd_la $period
+$V_BIN/v_upd_sys_rrd_net $period
+$V_BIN/v_upd_sys_rrd_mem $period
+$V_BIN/v_upd_sys_rrd_ssh $period
 
 # Updating web stats
 if [ "$WEB_SYSTEM" = 'apache' ]; then
-    $V_BIN/v_upd_sys_rrd_httpd
+    $V_BIN/v_upd_sys_rrd_httpd $period
 fi
 
 if [ "$PROXY_SYSTEM" = 'nginx' ]; then
-    $V_BIN/v_upd_sys_rrd_nginx
+    $V_BIN/v_upd_sys_rrd_nginx $period
 fi
 
 # Updating ftp stats
 if [ ! -z "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
-    $V_BIN/v_upd_sys_rrd_ftp
+    $V_BIN/v_upd_sys_rrd_ftp $period
 fi
 
 # Updating db stats
@@ -49,8 +52,8 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
     for type in ${DB_SYSTEM//,/ }; do
         # Switching on db type
         case $type in
-            mysql) $V_BIN/v_upd_sys_rrd_mysql ;;
-            pgsql) $V_BIN/v_upd_sys_rrd_pgsql ;;
+            mysql) $V_BIN/v_upd_sys_rrd_mysql $period ;;
+            pgsql) $V_BIN/v_upd_sys_rrd_pgsql $period ;;
         esac
     done
 fi

+ 17 - 9
bin/v_upd_sys_rrd_ftp

@@ -6,9 +6,8 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
@@ -19,6 +18,15 @@ source $V_CONF/vesta.conf
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/ftp" ]; then
     mkdir $V_RRD/ftp
@@ -40,7 +48,7 @@ if [ ! -e "$V_RRD/ftp/ftp.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
+if [ -z "$update" ]; then
     a=0
     a=$(ps aux |grep $FTP_SYSTEM |grep -v grep| grep -v nobody|\
         grep -v root|wc -l)
@@ -50,15 +58,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating rrd graph
-rrdtool graph $V_RRD/ftp/ftp.png \
+rrdtool graph $V_RRD/ftp/$period-ftp.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
-    --title "$(echo $FTP_SYSTEM|tr '[a-z]' '[A-Z]') Usage" \
+    --start "$start" \
+    --end "$end" \
+    --title "$(echo $FTP_SYSTEM|tr '[a-z]' '[A-Z]') Usage ($period)" \
     --vertical-label "Connections" \
-    --x-grid "$rrd_grid" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \

+ 19 - 14
bin/v_upd_sys_rrd_httpd

@@ -6,21 +6,27 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
-source $V_FUNC/shared.func
-source $V_FUNC/domain.func
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
+
 # Checking directory
 if [ ! -d "$V_RRD/web" ]; then
     mkdir $V_RRD/web
@@ -42,9 +48,8 @@ if [ ! -e "$V_RRD/web/httpd.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
-    web_port=$(get_config_value '$WEB_PORT')
-        server_status=$(wget -qO-  http://localhost:$web_port/server-status |\
+if [ -z "$update" ]; then
+    server_status=$(wget -qO-  http://localhost:$WEB_PORT/server-status |\
         grep 'currently being processed'| \
         cut -f 2 -d '>' |\
         sed 's/requests currently being processed, //' | \
@@ -58,15 +63,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating rrd graph
-rrdtool graph $V_RRD/web/httpd.png \
+rrdtool graph $V_RRD/web/$period-httpd.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
-    --title "HTTPD Usage" \
+    --start "$start" \
+    --end "$end" \
+    --title "HTTPD Usage ($period)" \
     --vertical-label "Connections" \
-    --x-grid "$rrd_grid" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \

+ 17 - 10
bin/v_upd_sys_rrd_la

@@ -6,19 +6,26 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/la" ]; then
     mkdir $V_RRD/la
@@ -41,7 +48,7 @@ if [ ! -e "$V_RRD/la/la.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
+if [ -z "$update" ]; then
     loadavg=$(cat /proc/loadavg )
     la=$(echo "$loadavg"|cut -f 2 -d ' ')
     pr=$(echo "$loadavg"|cut -f 4 -d ' '|cut -f 2 -d /)
@@ -51,15 +58,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating graph
-rrdtool graph $V_RRD/la/la.png \
+rrdtool graph $V_RRD/la/$period-la.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
-    --title "Load Average" \
+    --start "$start" \
+    --end "$end" \
+    --title "Load Average ($period)" \
     --vertical-label "Points" \
-    --x-grid "$rrd_grid" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \

+ 17 - 10
bin/v_upd_sys_rrd_mem

@@ -6,19 +6,26 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/mem" ]; then
     mkdir $V_RRD/mem
@@ -41,7 +48,7 @@ if [ ! -e "$V_RRD/mem/mem.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
+if [ -z "$update" ]; then
     mem=$(free -m)
     ram=$(echo "$mem" |awk '{print $3}'|head -n2 |tail -n1)
     swap=$(echo "$mem" |awk '{print $3}'|tail -n1)
@@ -51,15 +58,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating rrd graph
-rrdtool graph  $V_RRD/mem/mem.png \
+rrdtool graph  $V_RRD/mem/$period-mem.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
-    --title "Memory Usage" \
+    --start "$start" \
+    --end "$end" \
+    --title "Memory Usage ($period)" \
     --vertical-label "Mbytes" \
-    --x-grid "$rrd_grid" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \

+ 17 - 11
bin/v_upd_sys_rrd_mysql

@@ -6,21 +6,27 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 source $V_FUNC/shared.func
-source $V_FUNC/db.func
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/db" ]; then
     mkdir $V_RRD/db
@@ -58,7 +64,7 @@ for host in $hosts; do
             RRA:MAX:0.5:288:797
     fi
 
-    if [ -z "$1" ]; then
+    if [ -z "$update" ]; then
         # Defining host credentials
         host_str=$(grep "HOST='$host'" $conf)
         for key in $host_str; do
@@ -89,15 +95,15 @@ for host in $hosts; do
     fi
 
     # Updating daily graph
-    rrdtool graph  $V_RRD/db/mysql_$host.png \
+    rrdtool graph  $V_RRD/db/$period-mysql_$host.png \
         --imgformat PNG \
         --height="120" \
         --width="440" \
-        --start "$rrd_start" \
-        --end "$rrd_end" \
-        --title "MySQL Usage on $host" \
+        --start "$start" \
+        --end "$end" \
+        --title "MySQL Usage on $host ($period)" \
         --vertical-label "Queries" \
-        --x-grid "$rrd_grid" \
+        --x-grid "$grid" \
         -c "BACK#484439" \
         -c "SHADEA#484439" \
         -c "SHADEB#484439" \

+ 17 - 10
bin/v_upd_sys_rrd_net

@@ -6,19 +6,26 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/net" ]; then
     mkdir $V_RRD/net
@@ -50,7 +57,7 @@ for iface in $ifaces; do
     fi
 
     # Parsing device stats
-    if [ -z "$1" ]; then
+    if [ -z "$update" ]; then
         raw_iface=$(grep "$iface:" /proc/net/dev |sed -e "s/:/ /")
         rx=$(echo "$raw_iface" |awk '{print $2}')
         tx=$(echo "$raw_iface" |awk '{print $10}')
@@ -60,15 +67,15 @@ for iface in $ifaces; do
     fi
 
     # Updating rrd graph
-    rrdtool graph $V_RRD/net/$iface.png \
+    rrdtool graph $V_RRD/net/$period-$iface.png \
         --imgformat PNG \
         --height="120" \
         --width="440" \
-        --start "$rrd_start" \
-        --end "$rrd_end" \
-        --title "Bandwidth Usage $iface" \
+        --start "$start" \
+        --end "$end" \
+        --title "Bandwidth Usage $iface ($period)" \
         --vertical-label "KBytes" \
-        --x-grid "$rrd_grid" \
+        --x-grid "$grid" \
         -c "BACK#484439" \
         -c "SHADEA#484439" \
         -c "SHADEB#484439" \

+ 17 - 10
bin/v_upd_sys_rrd_nginx

@@ -6,19 +6,26 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/web" ]; then
     mkdir $V_RRD/web
@@ -40,7 +47,7 @@ if [ ! -e "$V_RRD/web/nginx.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
+if [ -z "$update" ]; then
     a=$(wget -qO-  http://localhost:8084/|head -n1|cut -f 3 -d ' ')
 
     # Updating rrd database
@@ -48,15 +55,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating rrd graph
-rrdtool graph $V_RRD/web/nginx.png \
+rrdtool graph $V_RRD/web/$period-nginx.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
-    --title "NGINX Usage" \
+    --start "$start" \
+    --end "$end" \
+    --title "NGINX Usage ($period)" \
     --vertical-label "Connections" \
-    --x-grid "$rrd_grid" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \

+ 17 - 11
bin/v_upd_sys_rrd_pgsql

@@ -6,21 +6,27 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 source $V_FUNC/shared.func
-source $V_FUNC/db.func
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/db" ]; then
     mkdir $V_RRD/db
@@ -58,7 +64,7 @@ for host in $hosts; do
             RRA:MAX:0.5:288:797
     fi
 
-    if [ -z "$1" ]; then
+    if [ -z "$update" ]; then
         # Defining host credentials
         host_str=$(grep "HOST='$host'" $conf)
         for key in $host_str; do
@@ -95,15 +101,15 @@ for host in $hosts; do
     fi
 
     # Updating rrd graph
-    rrdtool graph  $V_RRD/db/pgsql_$host.png \
+    rrdtool graph  $V_RRD/db/$period-pgsql_$host.png \
         --imgformat PNG \
         --height="120" \
         --width="440" \
-        --start "$rrd_start" \
-        --end "$rrd_end" \
-        --title "PostgreSQL Usage on $host" \
+        --start "$start" \
+        --end "$end" \
+        --title "PostgreSQL Usage on $host ($period)" \
         --vertical-label "Queries" \
-        --x-grid "$rrd_grid" \
+        --x-grid "$grid" \
         -c "BACK#484439" \
         -c "SHADEA#484439" \
         -c "SHADEB#484439" \

+ 17 - 10
bin/v_upd_sys_rrd_ssh

@@ -6,19 +6,26 @@
 #----------------------------------------------------------#
 
 # Argument defenition
-rrd_start=${1--1d}
-rrd_end=${2-now}
-rrd_grid=${3-MINUTE:30:HOUR:1:HOUR:4:0:%H:%M}
+update=$1
+period=${1-daily}
 
 # Importing variables
 source $VESTA/conf/vars.conf
-source $V_CONF/vesta.conf
 
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Switching on time period
+case $period in
+    daily)   start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';;
+    weekly)  start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';;
+    monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';;
+    yearly)  start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';;
+    *) exit $E_RRD_FAILED ;;
+esac
+
 # Checking directory
 if [ ! -d "$V_RRD/ssh" ]; then
     mkdir $V_RRD/ssh
@@ -40,7 +47,7 @@ if [ ! -e "$V_RRD/ssh/ssh.rrd" ]; then
 fi
 
 # Parsing data
-if [ -z "$1" ]; then
+if [ -z "$update" ]; then
     a=0
     a=$(ps auxf|grep sshd |grep -v grep |grep -v '/usr/sbin/'| wc -l)
 
@@ -49,15 +56,15 @@ if [ -z "$1" ]; then
 fi
 
 # Updating daily graph
-rrdtool graph $V_RRD/ssh/ssh.png \
+rrdtool graph $V_RRD/ssh/$period-ssh.png \
     --imgformat PNG \
     --height="120" \
     --width="440" \
-    --start "$rrd_start" \
-    --end "$rrd_end" \
+    --start "$start" \
+    --end "$end" \
     --title "SSH Usage" \
-    --vertical-label "Connections" \
-    --x-grid "$rrd_grid" \
+    --vertical-label "Connections ($period)" \
+    --x-grid "$grid" \
     -c "BACK#484439" \
     -c "SHADEA#484439" \
     -c "SHADEB#484439" \