def init():
"""Return top level command handler"""
@click.command()
@click.option('--cell', required=True,
envvar='TREADMILL_CELL',
callback=cli.handle_context_opt,
expose_value=False)
@click.option('--once', help='Run once.', is_flag=True, default=False)
@click.option('--interval', help='Wait interval between checks.',
default=_DEFAULT_INTERVAL)
@click.option('--threshold', help='Number of failed checks before reap.',
default=1)
@click.option('--proto', help='Endpoint protocol.', default='tcp',
type=click.Choice(['tcp', 'udp']))
@click.argument('pattern')
@click.argument('endpoint')
@click.argument('command', nargs=-1)
def reaper(once, interval, threshold, proto, pattern, endpoint, command):
"""Removes unhealthy instances of the app.
The health check script reads from STDIN and prints to STDOUT.
The input it list of instance host:port, similar to discovery.
Output - list of instances that did not pass health check.
For example, specifying awk '{print $1}' as COMMAND will remove all
instances.
"""
command = list(command)
failed = collections.Counter()
while True:
failed.update(_health_check(pattern, proto, endpoint, command))
for instance, count in failed.items():
_LOGGER.info('Failed: %s, count: %s', instance, count)
reaped = _reap([instance for instance, count in failed.items()
if count > threshold])
for instance in reaped:
del failed[instance]
if once:
break
time.sleep(utils.to_seconds(interval))
return reaper
评论列表
文章目录