Skip to content

Instantly share code, notes, and snippets.

@armon
Created February 21, 2015 01:10
Show Gist options
  • Save armon/c07e135c1c705a253cad to your computer and use it in GitHub Desktop.
Save armon/c07e135c1c705a253cad to your computer and use it in GitHub Desktop.
Reap Graphite nodes using Consul members
#!/bin/bash
# Store the live members
consul members | grep alive | awk '{ print $1 }' > /tmp/alive.txt
# Clean-up the collectd metrics
cd /data/graphite/whisper/collectd
ls | awk '{print substr($1, 0, index($1, "_node_")) }' > /tmp/monitored.txt
for NODE in `cat /tmp/monitored.txt`; do if grep -q $NODE /tmp/alive.txt; then echo $NODE alive; else echo $NODE dead; sudo rm -Rf ${NODE}_node_*; fi; done
# Cleanup the gauges
cd /data/graphite/whisper/statsite/gauges
for DIR in `ls`;
do
pushd $DIR
for NODE in `ls`; do if grep -q $NODE /tmp/alive.txt; then echo $NODE alive; else echo $NODE dead; sudo rm -Rf ${NODE}; fi; done
popd
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment