v-update-sys-rrd-ssh 2.6 KB

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