summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@omgwallhack.org>2012-09-08 18:29:48 -0700
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2012-09-08 18:29:48 -0700
commit8780b3be38657f80c457da0e568432f7ece3d0e0 (patch)
tree72ad81c8bbac5579f58fe9c480f84b71e3a4ca91 /etc
downloadfswarn-8780b3be38657f80c457da0e568432f7ece3d0e0.tar.gz
fswarn-8780b3be38657f80c457da0e568432f7ece3d0e0.zip
Initial commit: script and packaging
Diffstat (limited to 'etc')
-rwxr-xr-xetc/cron.hourly/fswarn42
-rw-r--r--etc/default/fswarn12
2 files changed, 54 insertions, 0 deletions
diff --git a/etc/cron.hourly/fswarn b/etc/cron.hourly/fswarn
new file mode 100755
index 0000000..82fe6df
--- /dev/null
+++ b/etc/cron.hourly/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}
+
diff --git a/etc/default/fswarn b/etc/default/fswarn
new file mode 100644
index 0000000..90608ac
--- /dev/null
+++ b/etc/default/fswarn
@@ -0,0 +1,12 @@
+## Defaults for the fswarn cron script, sourced by /etc/cron.hourly/fswarn on
+## Debian systems. Uncomment (remove the leading '#') and change values as
+## needed.
+
+## Percentage of filesystem utilization (block and inode) above which fswarn
+## will generate output. Defaults to 90.
+# THRESHOLD=90
+
+## The state file used to store previous runs so as to avoid repeated warnings.
+## Defaults to /var/lib/fswarn/state
+## Disable redundant warning suppression with /dev/null
+# STATEFILE=/var/lib/fswarn/state