04 July 2015

XenServer: Disk Space

NB: Also see my more generic Linux disk space post.

When XenServer runs out of disk space it just croaks, so big thanks to this post for pointing out this script which checks it and sends a message to the admin via the System Alerts in the XenCenter UI:
  1. Add a script to monitor disk space and report it to the XenCenter UI\
    #!/bin/bash
    # Quick And Dirty Disk Monitoring Utility
    # Get this host's UUID
    thisUUID='<YOUR SERVER UUID HERE>'
    # Threshold of disk usage to report on
    threshold=75    # an example of how much disk can be used before alerting
    # Get disk usage
    diskUsage=`df -h | grep "/$" | head -n 1 | awk {' print $5 '} | sed -n -e "s/%//p"`
    # Check
    if [ $diskUsage -gt $threshold ]; then
         xe message-create host-uuid=$thisUUID name="ROOT DISK USAGE" body="Disk space use has exceeded $diskUsage on `echo $HOSTNAME`!" priority="1"
    fi
  2. Make it executable:
    chmod +x /root/diskmonitor.sh
  3. Amend crontab to run the monitor periodically:
    1. crontab -e
    2. Paste in the following:
      00 00,06,12,18 * * * ./root/diskmonitor.sh

See where space is being used

df -h
sudo du -xm / | sort -rn

Freeing up Disk Space

  1. Delete log files in tmp
    cd /tmp/
    rm -rf *.log
  2. Delete archived log files in tmp:rm -rf /var/log/*gz
    or to do this recursively:
    To see what it will delete: find . -name "*log*.gz" -type f

    find . -name "*log*.gz" -type f -delete
  3. Destroy patches
    cd /var/patch; for p in ????????-????-????-????-????????????; do xe patch-destroy uuid=$p; done
  4. Amend /etc/logrotate.conf e.g. using a guide like this one on thegeekstuff.com

No comments:

Post a Comment