Skip to content

Instantly share code, notes, and snippets.

@jkapusi
Created December 22, 2014 13:09
Show Gist options
  • Save jkapusi/ac31602498d61e56ae4f to your computer and use it in GitHub Desktop.
Save jkapusi/ac31602498d61e56ae4f to your computer and use it in GitHub Desktop.
MogileFS rebalance workaround and MogileFS graphite reporter
#!/bin/bash
while :; do
mogadm check | cut -d] -f2- | awk '/writeable/{print "mogilefs."$1".free "$4" "systime()}' | nc -q0 graphite 2003
mogadm check | cut -d] -f2- | awk '/writeable/{print "mogilefs."$1".free_percent "int($5)" "systime()}' | nc -q0 graphite 2003
sleep `date "+60-%s%%60" | bc`
done
#!/bin/bash -x
# To run: while :; do ./mogilefs_rebalancer.sh; sleep 60; done
if mogadm rebalance status | grep -q "Rebalance is running"; then
exit 1;
fi
CURRENT_CLUSTER_USAGE=`mogadm check | awk '/total/{print int($5)}'`
DESTINATION_DEVS=`mogadm check | grep writeable | cut -d] -f2- | awk '{ n++; a[n,1] = $1; a[n,2] = $5 } END { for (i = 1; i <= n; i++) if (a[i,2] < (precentage-5)) printf "%s\n", substr(a[i,1], 4)}' precentage=$CURRENT_CLUSTER_USAGE | head -c-1 - | tr '\n' ','`
SOURCE_DEVS=`mogadm check | grep writeable | cut -d] -f2- | awk '{ n++; a[n,1] = $1; a[n,2] = $5 } END { for (i = 1; i <= n; i++) if (a[i,2] > (precentage+5)) printf "%s\n", substr(a[i,1], 4)}' precentage=$CURRENT_CLUSTER_USAGE | head -c-1 - | tr '\n' ','`
if [[ -z $DESTINATION_DEVS || -z $SOURCE_DEVS ]]; then
exit 1;
fi
mogadm rebalance policy --options="from_devices=$SOURCE_DEVS to_devices=$DESTINATION_DEVS limit_type=device limit_by=size limit=2g"
mogadm rebalance start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment