# HG changeset patch # User Dennis Fink # Date 2015-10-26 00:04:25 # Node ID 8c192f60f57f64ee9617cf38e3b27ef5140f45dc # Parent 3d53c627707a65bc94f875e3675f1c11edd8f409 Implemented --by-type in count stats diff --git a/ennstatus/cli/commands/stats.py b/ennstatus/cli/commands/stats.py --- a/ennstatus/cli/commands/stats.py +++ b/ennstatus/cli/commands/stats.py @@ -18,19 +18,23 @@ def stats(): @click.pass_obj def count(obj, by_type): - - def calculate_host_number(config, type='all'): + def calculate_host_number(config, type='all', servers=None): + hosts = set() if type == 'all': - hosts = set() - for values in config['ENNSTATUS_SERVERS'].values(): ips = frozenset(values['IPS']) hosts.add(ips) return len(hosts) - + else: + for server in servers[servertype]: + ips = frozenset( + config['ENNSTATUS_SERVERS'][server.name.lower()]['IPS'] + ) + hosts.add(ips) + return len(hosts) app = create_app() @@ -57,6 +61,38 @@ def count(obj, by_type): ) ) ) + else: + for servertype, server in servers.items(): + click.echo( + 'We have %s %s servers!' % ( + click.style( + str(len(server)), + fg='blue' + ), + click.style( + servertype, + fg='red' + ) + ) + ) + click.echo( + 'We have %s different %s hosts!' % ( + click.style( + str( + calculate_host_number( + app.config, + type=servertype, + servers=servers + ) + ), + fg='blue' + ), + click.style( + servertype, + fg='red' + ) + ) + ) @stats.command('countries')