123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #!/bin/bash
- #################################################################
- #
- # Plugin to monitor the size of a nextcloud instance including a
- # separate graph for all users
- #
- #################################################################
- #
- # Parameters understood:
- #
- # config (required)
- #
- #################################################################
- #
- # Requirements
- # - bash (or change first line to sh instead of bash or any other shell)
- # - existing and readable directory to scan
- # - du command, it exists on most of the *nix operating systems
- #
- #################################################################
- #
- # Configuration
- #
- # directory to of the nextcloud instance
- DIR="/var/www/vhosts/sebastianvendt.de/cloud.sebastianvendt.de"
- # unique id for every directory starting with 1 for the root directory
- ID=1;
- # - make sure that user/group that executes this script has access to the directory you have configured
- # otherwise run it as another user, edit plugins-conf.d/munin-node and stuff it with example below code (not suggested)
- # remember to remove hashes from the beginning of the lines
- #
- # [du]
- # user root
- #
- # - 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)
- # du -sm $DIR in MB
- # du -sk $DIR in KB
- #
- #################################################################
- #
- # Changelog
- #
- # Revision 0.1 SAT 16 Jan 2021 Sebastian Vendt
- # - initial release,
- #
- #################################################################
- #################################################################
- #################################################################
- #retrive the users
- USERS=$(find $DIR/data/ -maxdepth 1 -type d -printf "%f\n" | awk '!/updater/ && !/data/ && !/appdata/ && !/files_/ && !/__groupfolders/')
- if [ "$1" = "autoconf" ]; then
- if [ -d $DIR ]; then
- echo "yes"
- else
- echo "no (check your path)"
- fi
- exit 0
- fi
- if [ "$1" = "config" ]; then
- echo "graph_title Directory size of nextcloud instance"
- echo "graph_vlabel size MB"
- echo "graph_category nextcloud"
- echo "graph_info Size of $DIR and all seperate users"
- #root directory
- echo "dir$ID.label /"
- echo "dir$ID.min 0"
- echo "dir$ID.info Shows du -bs for overall nextcloud instance"
- for usr in $USERS; do
- ID=$(($ID+1))
- echo "dir$ID.label data/$usr"
- echo "dir$ID.min 0"
- echo "dir$ID.info Shows du -bs for the user"
- done;
- exit 0
- fi
- ID=1
- echo -n "dir$ID.value "
- if [ -d $DIR ]; then
- SIZE=`du -bs $DIR | cut -f1`
- echo $SIZE
- else
- echo "U"
- exit 1
- fi
- for usr in $USERS; do
- ID=$(($ID+1))
- echo -n "dir$ID.value "
- if [ -d $DIR/data/$usr ]; then
- SIZE=`du -bs $DIR/data/$usr | cut -f1`
- echo $SIZE
- else
- echo "U"
- exit 1
- fi
- done;
- exit 0
|