How to monitor which files are growing faster than other ones?
If you ever needed a tool to get to know which files are growing faster than other ones, you probably will be quite satisfied with this simple bash-script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/bin/sh # Checking the spool directory SPOOL=/var/spool/diskhogs if [ ! -e "${SPOOL}" ]; then mkdir -p "${SPOOL}" fi if [ ! -d "${SPOOL}" ]; then echo "There are no ${SPOOL} directory" >&2 exit 1 fi if [ -z "${1}" ]; then DIR=. else DIR="${1}" fi FILES=$(find "${DIR}" -type f) TIME=$(date +%s) if [ -z "${TIME}" ]; then echo "Can't determine current time" >&2 exit 1 fi for FILE in ${FILES}; do SIZE=$(ls -nl ${FILE} | awk '{ print $5 }') if [ -z "${SIZE}" ]; then echo "Can't determine size of the ${FILE} file" >&2 continue fi sqlite3 "${SPOOL}/db" "INSERT INTO sizes VALUES ('${FILE}', '${TIME}', '${SIZE}');" if [ ${?} -ne 0 ]; then continue fi done for PERIOD in 60 300 600 1800 3600 86400; do TIME_WAS=$((${TIME} - ${PERIOD})) ( echo "*** Since $(date --date="@${TIME_WAS}") (${PERIOD} seconds ago) ***" sqlite3 \ "${SPOOL}/db" \ "SELECT MAX(size) - MIN(size) AS mm, name FROM sizes WHERE time >= '${TIME_WAS}' GROUP BY name ORDER BY mm ;" ) > "${SPOOL}/report_${PERIOD}" done |
Simply […]