v-update-sys-rrd 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. # info: update system rrd charts
  3. # options: none
  4. #
  5. # The script is wrapper for all rrd functions. It updates all
  6. # v-update-sys-rrd_* at once.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Importing system enviroment as we run this script
  11. # mostly by cron wich do not read it by itself
  12. source /etc/profile
  13. # Includes
  14. source $VESTA/conf/vesta.conf
  15. source $VESTA/func/main.sh
  16. # Another workaround for cron enviroment
  17. PATH="$PATH:$BIN"
  18. export PATH
  19. # Checking rrddir
  20. if [ ! -d "$RRD" ]; then
  21. mkdir -p $RRD
  22. fi
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Checking daily period
  27. if [ -e "$RRD/daily.rrd" ]; then
  28. mtime=$(stat -c "%Y" $RRD/daily.rrd)
  29. ctime=$(date +%s)
  30. dtime=$((ctime - mtime))
  31. # Update every 5 minute
  32. if [ "$dtime" -gt '290' ]; then
  33. touch $RRD/daily.rrd
  34. periods="$periods daily"
  35. fi
  36. else
  37. touch $RRD/daily.rrd
  38. periods="$periods daily"
  39. fi
  40. # Checking weekly period
  41. if [ -e "$RRD/weekly.rrd" ]; then
  42. mtime=$(stat -c "%Y" $RRD/weekly.rrd)
  43. ctime=$(date +%s)
  44. dtime=$((ctime - mtime))
  45. # Update every hour
  46. if [ "$dtime" -gt '3590' ]; then
  47. touch $RRD/weekly.rrd
  48. periods="$periods weekly"
  49. fi
  50. else
  51. touch $RRD/weekly.rrd
  52. periods="$periods weekly"
  53. fi
  54. # Checking monthly period
  55. if [ -e "$RRD/monthly.rrd" ]; then
  56. mtime=$(stat -c "%Y" $RRD/monthly.rrd)
  57. ctime=$(date +%s)
  58. dtime=$((ctime - mtime))
  59. # Update every 6 hours
  60. if [ "$dtime" -gt '21590' ]; then
  61. touch $RRD/monthly.rrd
  62. periods="$periods monthly"
  63. fi
  64. else
  65. touch $RRD/monthly.rrd
  66. periods="$periods monthly"
  67. fi
  68. # Checking yearly period
  69. if [ -e "$RRD/yearly.rrd" ]; then
  70. mtime=$(stat -c "%Y" $RRD/yearly.rrd)
  71. ctime=$(date +%s)
  72. dtime=$((ctime - mtime))
  73. # Update every 12 hours
  74. if [ "$dtime" -gt '43190' ]; then
  75. touch $RRD/yearly.rrd
  76. periods="$periods yearly"
  77. fi
  78. else
  79. touch $RRD/yearly.rrd
  80. periods="$periods yearly"
  81. fi
  82. # Updateing system stats
  83. for period in $periods; do
  84. $BIN/v-update-sys-rrd-la $period
  85. $BIN/v-update-sys-rrd-net $period
  86. $BIN/v-update-sys-rrd-mem $period
  87. $BIN/v-update-sys-rrd-ssh $period
  88. # Updating web stats
  89. if [ "$WEB_SYSTEM" = 'apache' ]; then
  90. $BIN/v-update-sys-rrd-httpd $period
  91. fi
  92. if [ "$PROXY_SYSTEM" = 'nginx' ]; then
  93. $BIN/v-update-sys-rrd-nginx $period
  94. fi
  95. # Updating ftp stats
  96. if [ ! -z "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
  97. $BIN/v-update-sys-rrd-ftp $period
  98. fi
  99. # Updating db stats
  100. if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
  101. for type in ${DB_SYSTEM//,/ }; do
  102. # Switching on db type
  103. case $type in
  104. mysql) $BIN/v-update-sys-rrd-mysql $period ;;
  105. pgsql) $BIN/v-update-sys-rrd-pgsql $period ;;
  106. esac
  107. done
  108. fi
  109. done
  110. #----------------------------------------------------------#
  111. # Vesta #
  112. #----------------------------------------------------------#
  113. # No Logging
  114. #log_event "$OK" "$EVENT"
  115. exit