v-update-sys-rrd-ftp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # info: update ftp rrd
  3. # options: PERIOD
  4. #
  5. # The function is for updating ftpd rrd database and graphic.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. period=${1-daily}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. source $VESTA/conf/vesta.conf
  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/ftp" ]; then
  27. mkdir $RRD/ftp
  28. fi
  29. # Checking database
  30. if [ ! -e "$RRD/ftp/ftp.rrd" ]; then
  31. # Adding database
  32. rrdtool create $RRD/ftp/ftp.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. a=0
  46. a=$(ps aux |grep $FTP_SYSTEM |grep -v grep| grep -v nobody|\
  47. grep -v root|wc -l)
  48. # Updating rrd database
  49. rrdtool update $RRD/ftp/ftp.rrd N:$a
  50. fi
  51. # Updating rrd graph
  52. rrdtool graph $RRD/ftp/$period-ftp.png \
  53. --imgformat PNG \
  54. --height="150" \
  55. --width="670" \
  56. --start "$start" \
  57. --end "$end" \
  58. --vertical-label "Connections" \
  59. --x-grid "$grid" \
  60. -c "BACK#ffffff" \
  61. -c "SHADEA#ffffff" \
  62. -c "SHADEB#ffffff" \
  63. -c "FONT#555555" \
  64. -c "CANVAS#302c2d" \
  65. -c "GRID#666666" \
  66. -c "MGRID#AAAAAA" \
  67. -c "FRAME#302c2d" \
  68. -c "ARROW#FFFFFF" \
  69. DEF:a=$RRD/ftp/ftp.rrd:A:AVERAGE \
  70. COMMENT:'\r' \
  71. LINE1:a#fefda0:"Users " \
  72. GPRINT:a:'LAST:Current\:''%8.0lf' \
  73. GPRINT:a:'MIN:Min\:''%8.0lf' \
  74. GPRINT:a:'MAX:Max\:''%8.0lf\j' &>/dev/null; result=$?
  75. #----------------------------------------------------------#
  76. # Vesta #
  77. #----------------------------------------------------------#
  78. if [ "$result" -ne 0 ]; then
  79. exit $E_RRD
  80. fi
  81. exit