From 94c5c402c64347efa26a6d358cdc7ad4bb0146ef Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 28 Nov 2014 15:42:27 -0800 Subject: [PATCH] reports: new project-disk-use.sh report Reports total disk used by projects sorted in descending piggish order. --- cron/girocco | 3 ++ install.sh | 4 +- toolbox/{inactive => inactive.sh} | 0 toolbox/reports/project-disk-use.sh | 96 +++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) rename toolbox/{inactive => inactive.sh} (100%) create mode 100755 toolbox/reports/project-disk-use.sh diff --git a/cron/girocco b/cron/girocco index 4d786e8..97c94cb 100644 --- a/cron/girocco +++ b/cron/girocco @@ -53,6 +53,9 @@ # Nine rotating backups are kept, run this more often if needed. 19 5 * * * repo "$HOME/repomgr/toolbox/backup-db.sh" +# Report project disk space usage once a week with an email to admin +#23 7 * * 3 repo "$HOME/repomgr/toolbox/reports/project-disk-use.sh" -m 100 + # The job daemon and task daemon are run in a screen # The ../screen/screenrc file needs to be installed to # ~repo/.screenrc to support the SCREENCOMMAND functionality. diff --git a/install.sh b/install.sh index f4581b0..880abc7 100755 --- a/install.sh +++ b/install.sh @@ -125,7 +125,9 @@ perl -I. -M$GIROCCO_CONF -i -p \ "$cfg_basedir"/jobs/*.sh "$cfg_basedir"/jobd/*.sh \ "$cfg_basedir"/taskd/*.sh "$cfg_basedir"/gitweb/*.sh \ "$cfg_basedir"/shlib.sh "$cfg_basedir"/hooks/* \ - "$cfg_basedir"/toolbox/* "$cfg_basedir"/bin/git-* \ + "$cfg_basedir"/toolbox/*.sh "$cfg_basedir"/toolbox/*.pl \ + "$cfg_basedir"/toolbox/reports/*.sh \ + "$cfg_basedir"/bin/git-* \ "$cfg_basedir"/bin/create-* "$cfg_basedir"/bin/update-* \ "$cfg_basedir"/bin/authrequired.cgi "$cfg_basedir"/screen/* diff --git a/toolbox/inactive b/toolbox/inactive.sh similarity index 100% rename from toolbox/inactive rename to toolbox/inactive.sh diff --git a/toolbox/reports/project-disk-use.sh b/toolbox/reports/project-disk-use.sh new file mode 100755 index 0000000..2a761fa --- /dev/null +++ b/toolbox/reports/project-disk-use.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# Report on project disk use. +# Output can be sent as email to admin with -m +# Automatically runs with nice and ionice (if available) + +# Usage: project-disk-use [-m] [top-n-only] + +# With -m mail the report to $cfg_admin instead of sending it to stdout + +# Shows total disk usage in K bytes for $cfg_reporoot +# The top-n-only (all if not given) repos are then listed by +# decreasing order of disk space. + +# Note that any *.git directories that are found in $cfg_reporoot that are +# not listed in $cfg_chroot/etc/group ARE included and have a '!' suffix added. + +set -e + +datefmt='%Y-%m-%d %H:%M:%S %z' +startdate="$(date "+$datefmt")" + +. @basedir@/shlib.sh + +mailresult= +if [ "$1" = "-m" ]; then + shift + mailresult=1 +fi + +hasnice= +command -v nice > /dev/null && hasnice=1 +hasionice= +command -v ionice > /dev/null && hasionice=1 + +get_use_k() { + _cmd="du -k -s \"$1\" | cut -f 1" + [ -n "$hasionice" ] && _cmd="ionice -c 3 $_cmd" + [ -n "$hasnice" ] && _cmd="nice -n 19 $_cmd" + eval "$_cmd" +} + +projlist="$(cut -d : -f 1 < "$cfg_chroot/etc/group")" + +is_listed_proj() { + echo "$projlist" | grep -q -e "^$1$" +} + +cd "$cfg_reporoot" +total=0 +results= +while IFS='' read -r proj; do + proj="${proj#./}" + proj="${proj%.git}" + x= + is_listed_proj "$proj" || x='!' + usek="$(get_use_k "$proj.git")" + total="$(( $total + $usek ))" + line="$(printf '%8d\t%s%s\n*' "$usek" "$proj" "$x")" + line="${line%?}" + results="$results$line" +done <