diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | etc/cron.hourly/fswarn | 42 | ||||
-rwxr-xr-x | sbin/fswarn | 42 |
3 files changed, 48 insertions, 42 deletions
@@ -3,6 +3,8 @@ build: install: install -o root -g root -m 755 -d $(DESTDIR)/etc/cron.hourly install -o root -g root -m 755 -d $(DESTDIR)/etc/default - install -o root -g root -m 755 etc/cron.hourly/fswarn $(DESTDIR)/etc/cron.hourly - install -o root -g root -m 644 etc/default/fswarn $(DESTDIR)/etc/default/fswarn + install -o root -g root -m 755 -d $(DESTDIR)/usr/sbin + install -o root -g root -m 755 etc/cron.hourly/fswarn $(DESTDIR)/etc/cron.hourly/ + install -o root -g root -m 644 etc/default/fswarn $(DESTDIR)/etc/default/ + install -o root -g root -m 644 sbin/fswarn $(DESTDIR)/usr/sbin/ clean: diff --git a/etc/cron.hourly/fswarn b/etc/cron.hourly/fswarn index 82fe6df..8a953e5 100755..100644 --- a/etc/cron.hourly/fswarn +++ b/etc/cron.hourly/fswarn @@ -1,42 +1,4 @@ #!/bin/sh -# statf() warning system intended for use with cron - -#set -x - -if ! grep -q /usr/bin/lckdo /proc/$PPID/cmdline; then - exec /usr/bin/lckdo /run/fswarn $0 "$@"; -fi - -THRESHOLD=90 -STATEFILE=/var/lib/fswarn/state - -[ -s /etc/default/fswarn ] && . /etc/default/fswarn - -trap 'rm ${STATETEMP}' EXIT -STATETEMP=$(mktemp fswarn.XXXXXXXX) - -for i in $( grep -E ' ('$( for FSTYPE in $( grep -v ^nodev /proc/filesystems ); do echo -n "$FSTYPE|"; done; echo -n "ramfs|tmpfs" )') ' /proc/mounts | cut -f 2 -d ' ' | sort -u ); do - BLOCKFREE=$( stat -f -c %a $i ) - BLOCKTOTAL=$( stat -f -c %b $i ) - BLOCKALLOC=$(( ${BLOCKTOTAL} - ${BLOCKFREE} )) - BLOCKPERCENT=$(( 100 * ${BLOCKALLOC} / ${BLOCKTOTAL} )) - BLOCKOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 4 -d ' ' | grep . ) 2>/dev/null || BLOCKOLDPERCENT=0 - if [ ${BLOCKPERCENT} -gt ${BLOCKOLDPERCENT} ] && [ ${BLOCKPERCENT} -gt ${THRESHOLD} ] ; then - echo "WARNING: $i is at %${BLOCKPERCENT} block utilization!" > /dev/stderr - fi - echo -n "$i ${BLOCKALLOC} ${BLOCKTOTAL} ${BLOCKPERCENT}" - INODEFREE=$( stat -f -c %d $i ) - INODETOTAL=$( stat -f -c %c $i ) - if [ $INODETOTAL -gt 0 ]; then - INODEALLOC=$(( ${INODETOTAL} - ${INODEFREE} )) - INODEPERCENT=$(( 100 * ${INODEALLOC} / ${INODETOTAL} )) - INODEOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 7 -d ' ' | grep . ) 2>/dev/null || INODEOLDPERCENT=0 - if [ ${INODEPERCENT} -gt ${INODEOLDPERCENT} ] && [ ${INODEPERCENT} -gt ${THRESHOLD} ] ; then - echo "WARNING: $i is at %${INODEPERCENT} inode utilization!" > /dev/stderr - fi - echo -n " ${INODEALLOC} ${INODETOTAL} ${INODEPERCENT}" - fi - echo -done > ${STATETEMP} -cp ${STATETEMP} ${STATEFILE} +test -x /usr/sbin/fswarn || exit 0 +/usr/sbin/fswarn diff --git a/sbin/fswarn b/sbin/fswarn new file mode 100755 index 0000000..82fe6df --- /dev/null +++ b/sbin/fswarn @@ -0,0 +1,42 @@ +#!/bin/sh +# statf() warning system intended for use with cron + +#set -x + +if ! grep -q /usr/bin/lckdo /proc/$PPID/cmdline; then + exec /usr/bin/lckdo /run/fswarn $0 "$@"; +fi + +THRESHOLD=90 +STATEFILE=/var/lib/fswarn/state + +[ -s /etc/default/fswarn ] && . /etc/default/fswarn + +trap 'rm ${STATETEMP}' EXIT +STATETEMP=$(mktemp fswarn.XXXXXXXX) + +for i in $( grep -E ' ('$( for FSTYPE in $( grep -v ^nodev /proc/filesystems ); do echo -n "$FSTYPE|"; done; echo -n "ramfs|tmpfs" )') ' /proc/mounts | cut -f 2 -d ' ' | sort -u ); do + BLOCKFREE=$( stat -f -c %a $i ) + BLOCKTOTAL=$( stat -f -c %b $i ) + BLOCKALLOC=$(( ${BLOCKTOTAL} - ${BLOCKFREE} )) + BLOCKPERCENT=$(( 100 * ${BLOCKALLOC} / ${BLOCKTOTAL} )) + BLOCKOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 4 -d ' ' | grep . ) 2>/dev/null || BLOCKOLDPERCENT=0 + if [ ${BLOCKPERCENT} -gt ${BLOCKOLDPERCENT} ] && [ ${BLOCKPERCENT} -gt ${THRESHOLD} ] ; then + echo "WARNING: $i is at %${BLOCKPERCENT} block utilization!" > /dev/stderr + fi + echo -n "$i ${BLOCKALLOC} ${BLOCKTOTAL} ${BLOCKPERCENT}" + INODEFREE=$( stat -f -c %d $i ) + INODETOTAL=$( stat -f -c %c $i ) + if [ $INODETOTAL -gt 0 ]; then + INODEALLOC=$(( ${INODETOTAL} - ${INODEFREE} )) + INODEPERCENT=$(( 100 * ${INODEALLOC} / ${INODETOTAL} )) + INODEOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 7 -d ' ' | grep . ) 2>/dev/null || INODEOLDPERCENT=0 + if [ ${INODEPERCENT} -gt ${INODEOLDPERCENT} ] && [ ${INODEPERCENT} -gt ${THRESHOLD} ] ; then + echo "WARNING: $i is at %${INODEPERCENT} inode utilization!" > /dev/stderr + fi + echo -n " ${INODEALLOC} ${INODETOTAL} ${INODEPERCENT}" + fi + echo +done > ${STATETEMP} +cp ${STATETEMP} ${STATEFILE} + |