v_list_sys_rrd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_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 $V_RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
  19. if [ "$i" -ne 1 ]; then
  20. echo -e "\t},"
  21. fi
  22. # Define title
  23. if [ "$type" = 'la' ]; then
  24. title="Load Average"
  25. fi
  26. if [ "$type" = 'mem' ]; then
  27. title="Memory Usage"
  28. fi
  29. if [ "$type" = 'net' ]; then
  30. title="Bandwidth Usage $rrd"
  31. fi
  32. if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\
  33. [ "$type" = 'ssh' ]; then
  34. title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage"
  35. fi
  36. if [ "$type" = 'db' ]; then
  37. db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
  38. -e 's/pgsql/PostgreSQL/g' )
  39. db_host=$(echo $rrd|cut -f 2 -d _ )
  40. title="$db_type Usage on $db_host"
  41. fi
  42. echo -e "\t\"$i\": {"
  43. echo -e "\t\t\"TYPE\": \"$type\"",
  44. echo -e "\t\t\"RRD\": \"$rrd\"",
  45. echo -e "\t\t\"TITLE\": \"$title\""
  46. (( ++i))
  47. done
  48. done
  49. if [ "$i" -gt 1 ]; then
  50. echo -e "\t}"
  51. fi
  52. echo "}"
  53. }
  54. # Define jshell function
  55. shell_list_rrd() {
  56. if [ -z "$nohead" ]; then
  57. # Print brief info
  58. echo "PATH"
  59. echo "---------"
  60. fi
  61. for type in $rrd_types; do
  62. for rrd in $(ls $V_RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
  63. echo "$V_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