du_nextcloud 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. #################################################################
  3. #
  4. # Plugin to monitor the size of a nextcloud instance including a
  5. # separate graph for all users
  6. #
  7. #################################################################
  8. #
  9. # Parameters understood:
  10. #
  11. # config (required)
  12. #
  13. #################################################################
  14. #
  15. # Requirements
  16. # - bash (or change first line to sh instead of bash or any other shell)
  17. # - existing and readable directory to scan
  18. # - du command, it exists on most of the *nix operating systems
  19. #
  20. #################################################################
  21. #
  22. # Configuration
  23. #
  24. # directory to of the nextcloud instance
  25. DIR="/var/www/vhosts/sebastianvendt.de/cloud.sebastianvendt.de"
  26. # unique id for every directory starting with 1 for the root directory
  27. ID=1;
  28. # - make sure that user/group that executes this script has access to the directory you have configured
  29. # otherwise run it as another user, edit plugins-conf.d/munin-node and stuff it with example below code (not suggested)
  30. # remember to remove hashes from the beginning of the lines
  31. #
  32. # [du]
  33. # user root
  34. #
  35. # - by default the value is in MegaBytes, to change it you should edit below line in the script to something else, recognizable by du (see man du)
  36. # du -sm $DIR in MB
  37. # du -sk $DIR in KB
  38. #
  39. #################################################################
  40. #
  41. # Changelog
  42. #
  43. # Revision 0.1 SAT 16 Jan 2021 Sebastian Vendt
  44. # - initial release,
  45. #
  46. #################################################################
  47. #################################################################
  48. #################################################################
  49. #retrive the users
  50. USERS=$(find $DIR/data/ -maxdepth 1 -type d -printf "%f\n" | awk '!/updater/ && !/data/ && !/appdata/ && !/files_/ && !/__groupfolders/')
  51. if [ "$1" = "autoconf" ]; then
  52. if [ -d $DIR ]; then
  53. echo "yes"
  54. else
  55. echo "no (check your path)"
  56. fi
  57. exit 0
  58. fi
  59. if [ "$1" = "config" ]; then
  60. echo "graph_title Directory size of nextcloud instance"
  61. echo "graph_vlabel size MB"
  62. echo "graph_category nextcloud"
  63. echo "graph_info Size of $DIR and all seperate users"
  64. #root directory
  65. echo "dir$ID.label /"
  66. echo "dir$ID.min 0"
  67. echo "dir$ID.info Shows du -bs for overall nextcloud instance"
  68. for usr in $USERS; do
  69. ID=$(($ID+1))
  70. echo "dir$ID.label data/$usr"
  71. echo "dir$ID.min 0"
  72. echo "dir$ID.info Shows du -bs for the user"
  73. done;
  74. exit 0
  75. fi
  76. ID=1
  77. echo -n "dir$ID.value "
  78. if [ -d $DIR ]; then
  79. SIZE=`du -bs $DIR | cut -f1`
  80. echo $SIZE
  81. else
  82. echo "U"
  83. exit 1
  84. fi
  85. for usr in $USERS; do
  86. ID=$(($ID+1))
  87. echo -n "dir$ID.value "
  88. if [ -d $DIR/data/$usr ]; then
  89. SIZE=`du -bs $DIR/data/$usr | cut -f1`
  90. echo $SIZE
  91. else
  92. echo "U"
  93. exit 1
  94. fi
  95. done;
  96. exit 0