v_update_sys_rrd_ssh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # info: update ssh rrd
  3. # options: period
  4. #
  5. # The function is for updating ssh 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/shared.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/ssh" ]; then
  27. mkdir $RRD/ssh
  28. fi
  29. # Checking database
  30. if [ ! -e "$RRD/ssh/ssh.rrd" ]; then
  31. # Adding database
  32. rrdtool create $RRD/ssh/ssh.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 auxf|grep sshd |grep -v grep |grep -v '/usr/sbin/'| wc -l)
  47. # Updating rrd database
  48. rrdtool update $RRD/ssh/ssh.rrd N:$a
  49. fi
  50. # Updating daily graph
  51. rrdtool graph $RRD/ssh/$period-ssh.png \
  52. --imgformat PNG \
  53. --height="120" \
  54. --width="440" \
  55. --start "$start" \
  56. --end "$end" \
  57. --vertical-label "Connections" \
  58. --x-grid "$grid" \
  59. -c "BACK#7a766d" \
  60. -c "SHADEA#7a766d" \
  61. -c "SHADEB#7a766d" \
  62. -c "FONT#FFFFFF" \
  63. -c "CANVAS#302c2d" \
  64. -c "GRID#666666" \
  65. -c "MGRID#AAAAAA" \
  66. -c "FRAME#302c2d" \
  67. -c "ARROW#FFFFFF" \
  68. DEF:a=$RRD/ssh/ssh.rrd:A:AVERAGE \
  69. COMMENT:'\r' \
  70. LINE1:a#fefda0:"Users " \
  71. GPRINT:a:'LAST:Current\:''%8.0lf' \
  72. GPRINT:a:'MIN:Min\:''%8.0lf' \
  73. GPRINT:a:'MAX:Max\:''%8.0lf\j' &>/dev/null; result=$?
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. if [ "$result" -ne 0 ]; then
  78. exit $E_RRD
  79. fi
  80. exit