Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Clean up Whisper files that no longer map to this host.

View whisper-clean.py
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
import os
import os.path
import sys
 
from graphite.render.hashing import ConsistentHashRing
 
instances = []
unwelcome_instances = []
for arg in sys.argv[1:]:
unwelcome = False
if arg.startswith('-'):
arg = arg[1:]
unwelcome = True
instance = tuple(arg.split(':', 2))
instances.append(instance)
if unwelcome:
unwelcome_instances.append(instance)
if 0 == len(instances):
print('Usage: python whisper-clean.py [-]<address>:<instance>[...]')
sys.exit(1)
 
ring = ConsistentHashRing(instances)
 
for dirname, dirnames, filenames in os.walk('/var/lib/graphite/whisper'):
for filename in filenames:
pathname = os.path.join(dirname, filename)
basename, ext = os.path.splitext(filename)
if '.wsp' != ext:
print('skipping %s' % os.path.relpath(pathname,
'/var/lib/graphite/whisper'))
if ring.get_node(os.path.relpath(os.path.join(dirname, basename),
'/var/lib/graphite/whisper').
replace('/', '.')) in unwelcome_instances:
print('unlinking %s' % pathname)
os.unlink(pathname)

Should there be a continue after line 30?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.