v-list-sys-rrd 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. # info: list system rrd charts
  3. # options: [FORMAT]
  4. #
  5. # List available rrd graphics, its titles and paths.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. format=${1-shell}
  10. # Includes
  11. source $VESTA/func/main.sh
  12. source $VESTA/conf/vesta.conf
  13. # Define json function
  14. json_list_rrd() {
  15. i=1
  16. echo "{"
  17. for type in $rrd_types; do
  18. for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
  19. if [ "$i" -ne 1 ]; then
  20. echo -e "\t},"
  21. fi
  22. if [ "$type" = 'la' ]; then
  23. title="Load Average"
  24. fi
  25. if [ "$type" = 'mem' ]; then
  26. title="Memory Usage"
  27. fi
  28. if [ "$type" = 'net' ]; then
  29. title="Bandwidth Usage $rrd"
  30. fi
  31. if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\
  32. [ "$type" = 'ssh' ]; then
  33. title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage"
  34. fi
  35. if [ "$type" = 'mail' ]; then
  36. title="Exim Usage"
  37. fi
  38. if [ "$type" = 'db' ]; then
  39. db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
  40. -e 's/pgsql/PostgreSQL/g' )
  41. db_host=$(echo $rrd|cut -f 2 -d _ )
  42. title="$db_type Usage on $db_host"
  43. fi
  44. echo -e "\t\"$i\": {"
  45. echo -e "\t\t\"TYPE\": \"$type\"",
  46. echo -e "\t\t\"RRD\": \"$rrd\"",
  47. echo -e "\t\t\"TITLE\": \"$title\","
  48. echo -e "\t\t\"TIME\": \"$TIME\","
  49. echo -e "\t\t\"DATE\": \"$DATE\""
  50. (( ++i))
  51. done
  52. done
  53. if [ "$i" -gt 1 ]; then
  54. echo -e "\t}"
  55. fi
  56. echo "}"
  57. }
  58. # Define jshell function
  59. shell_list_rrd() {
  60. if [ -z "$nohead" ]; then
  61. echo "PATH"
  62. echo "---------"
  63. fi
  64. for type in $rrd_types; do
  65. for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
  66. echo "$RRD/$type/$rrd.rrd"
  67. done
  68. done
  69. }
  70. #----------------------------------------------------------#
  71. # Action #
  72. #----------------------------------------------------------#
  73. # Checking enabled systems
  74. rrd_types="la mem net"
  75. if [ -n "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
  76. rrd_types="$rrd_types web"
  77. fi
  78. if [ -n "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
  79. rrd_types="$rrd_types mail"
  80. fi
  81. if [ -n "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
  82. rrd_types="$rrd_types db"
  83. fi
  84. if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
  85. rrd_types="$rrd_types ftp"
  86. fi
  87. rrd_types="$rrd_types ssh"
  88. # Listing domains
  89. case $format in
  90. json) json_list_rrd ;;
  91. plain) nohead=1; shell_list_rrd ;;
  92. shell) shell_list_rrd | column -t ;;
  93. esac
  94. #----------------------------------------------------------#
  95. # Vesta #
  96. #----------------------------------------------------------#
  97. exit