v-list-sys-rrd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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" = 'db' ]; then
  36. db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
  37. -e 's/pgsql/PostgreSQL/g' )
  38. db_host=$(echo $rrd|cut -f 2 -d _ )
  39. title="$db_type Usage on $db_host"
  40. fi
  41. echo -e "\t\"$i\": {"
  42. echo -e "\t\t\"TYPE\": \"$type\"",
  43. echo -e "\t\t\"RRD\": \"$rrd\"",
  44. echo -e "\t\t\"TITLE\": \"$title\","
  45. echo -e "\t\t\"TIME\": \"$TIME\","
  46. echo -e "\t\t\"DATE\": \"$DATE\""
  47. (( ++i))
  48. done
  49. done
  50. if [ "$i" -gt 1 ]; then
  51. echo -e "\t}"
  52. fi
  53. echo "}"
  54. }
  55. # Define jshell function
  56. shell_list_rrd() {
  57. if [ -z "$nohead" ]; then
  58. echo "PATH"
  59. echo "---------"
  60. fi
  61. for type in $rrd_types; do
  62. for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
  63. echo "$RRD/$type/$rrd.rrd"
  64. done
  65. done
  66. }
  67. #----------------------------------------------------------#
  68. # Action #
  69. #----------------------------------------------------------#
  70. # Checking enabled systems
  71. rrd_types="la mem net"
  72. if [ -n "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
  73. rrd_types="$rrd_types web"
  74. fi
  75. if [ -n "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
  76. rrd_types="$rrd_types db"
  77. fi
  78. if [ -n "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
  79. rrd_types="$rrd_types mail"
  80. fi
  81. if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
  82. rrd_types="$rrd_types ftp"
  83. fi
  84. rrd_types="$rrd_types ssh"
  85. # Listing domains
  86. case $format in
  87. json) json_list_rrd ;;
  88. plain) nohead=1; shell_list_rrd ;;
  89. shell) shell_list_rrd | column -t ;;
  90. esac
  91. #----------------------------------------------------------#
  92. # Vesta #
  93. #----------------------------------------------------------#
  94. exit