v_update_sys_rrd_httpd 2.8 KB

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