-
-
Save charz/57e3cbcd7c712ce47305e3c796d50f51 to your computer and use it in GitHub Desktop.
check on the expirer queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from collections import defaultdict | |
import sys | |
import time | |
import socket | |
from argparse import ArgumentParser | |
from swift.common.internal_client import InternalClient | |
from swift.common.utils import Timestamp | |
from swift.common.wsgi import ConfigString | |
from swift.container.sync import ic_conf_body | |
from swift.obj.expirer import parse_task_obj | |
parser = ArgumentParser() | |
parser.add_argument('-v', '--verbose', action='store_true', | |
help='more detailed info') | |
parser.add_argument('--objects-container-divisor', type=int, default=86400, | |
help='The window size for pending expirations') | |
parser.add_argument('-d', '--details', action='store_true', | |
help='more detailed counts') | |
parser.add_argument('--metrics', help='file name to dump metrics') | |
def dump_metrics(filename, stats): | |
host = stats.pop('hostname') | |
with open(filename, 'w') as f: | |
for key, value in stats.items(): | |
f.write('expiring_objects_entries{host="%s",stats="%s"} %s\n' % ( | |
host, key, value)) | |
def main(): | |
args = parser.parse_args() | |
now = time.time() | |
t_now = Timestamp.now() | |
expiring_account = '.expiring_objects' | |
conf = ConfigString(ic_conf_body) | |
swift = InternalClient(conf, 'swift-expirer-status', 1) | |
stats = defaultdict(int) | |
stats['hostname'] = socket.gethostname() | |
stats['total'] = 0 | |
stats['pending'] = 0 | |
stats['stale'] = 0 | |
for container_item in swift.iter_containers(expiring_account): | |
if args.verbose: | |
print ('%s/' % expiring_account + | |
'%(name)s: %(count)s' % container_item) | |
try: | |
container = int(container_item['name']) | |
except ValueError: | |
continue | |
stats['total'] += container_item['count'] | |
if container < now: | |
if container < (now - args.objects_container_divisor): | |
stats['stale'] += container_item['count'] | |
else: | |
if not args.details: | |
stats['pending'] += container_item['count'] | |
continue | |
for object_item in swift.iter_objects( | |
expiring_account, container_item['name']): | |
if args.verbose: | |
print '%(name)s: %(content_type)s' % object_item | |
# this should probably be done in parse_task_obj | |
task_object = object_item['name'].encode('utf8') | |
delete_timestamp, _target_account, _target_container, \ | |
_target_object = parse_task_obj(task_object) | |
if t_now > delete_timestamp: | |
stats['stale'] += 1 | |
else: | |
stats['pending'] += 1 | |
if args.metrics: | |
dump_metrics(args.metrics, stats) | |
else: | |
print ' Total entries: %(total)s' % stats | |
print 'Pending entries: %(pending)s' % stats | |
print ' Stale entries: %(stale)s' % stats | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment