Thursday, September 13, 2012

Monitor big files in linux servers

You can proactively use this script to be informed whenever things go wrong. Here are some examples:
$ ./assert-no-big-files.sh 1G
-rw-r----- 1 root adm 3.3G Sep  9 06:27 /var/log/apache2/mod-jk.log.1
-rw-r----- 1 root adm 3.3G Sep 13 11:50 /var/log/apache2/mod-jk.log.todelete
$ ./assert-no-big-files.sh 1000M
-rw-r----- 1 root adm 3.3G Sep  9 06:27 /var/log/apache2/mod-jk.log.1
-rw-r----- 1 root adm 3.3G Sep 13 11:50 /var/log/apache2/mod-jk.log.todelete
$ ./assert-no-big-files.sh 1000000k
-rw-r----- 1 root adm 3.3G Sep  9 06:27 /var/log/apache2/mod-jk.log.1
-rw-r----- 1 root adm 3.3G Sep 13 11:50 /var/log/apache2/mod-jk.log.todelete
I have found monit very useful on this as it will send an alert when the issue is detected while it will not send it again until is back to normal. Just build a wrapper to look let us say for files bigger than 250MB:
#!/bin/bash -e
# assert-no-files-bigger-than-250MB.sh
/bin/assert-no-big-files.sh 250M
Then add the script to monit:
#################################################################
#Big files
################################################################
check program assert-no-files-bigger-than-250MB with path "/bin/assert-no-files-bigger-than-250MB.sh"
  if status != 0 then alert

No comments:

Followers