v-update-sys-rrd-apache2 2.9 KB

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