v-update-sys-rrd-httpd 2.8 KB

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