v-update-sys-rrd-apache2 3.0 KB

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