v-update-sys-rrd-ssh 2.7 KB

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