v_update_sys_rrd_httpd 2.8 KB

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