コード例 #1
0
ファイル: metrics.py プロジェクト: stephamon/otter
def get_tenant_metrics(tenant_id, scaling_groups, grouped_servers,
                       _print=False):
    """
    Produce per-group metrics for all the groups of a tenant

    :param list scaling_groups: Tenant's scaling groups as dict from CASS
    :param dict grouped_servers: Servers from Nova grouped based on
        scaling group ID.
    :return: generator of (tenantId, groupId, desired, actual) GroupMetrics
    """
    if _print:
        print('processing tenant {} with groups {} and servers {}'.format(
              tenant_id, len(scaling_groups), len(grouped_servers)))

    groups = {g['groupId']: g for g in scaling_groups}

    for group_id in set(groups.keys() + grouped_servers.keys()):
        servers = grouped_servers.get(group_id, [])
        if group_id in groups:
            group = groups[group_id]
            if group.get("status") in ("ERROR", "DISABLED"):
                continue
        else:
            group = {'groupId': group_id_from_metadata(servers[0]['metadata']),
                     'desired': 0}
        servers = map(NovaServer.from_server_details_json, servers)
        counts = defaultdict(lambda: 0)
        counts.update(countby(get_destiny, servers))
        active = counts[Destiny.CONSIDER_AVAILABLE] + \
            counts[Destiny.AVOID_REPLACING]
        ignore = counts[Destiny.DELETE] + counts[Destiny.CLEANUP] + \
            counts[Destiny.IGNORE]
        yield GroupMetrics(tenant_id, group['groupId'], group['desired'],
                           active, len(servers) - ignore - active)
コード例 #2
0
def histogram(results):
    from toolz import recipes, dicttoolz
    import math
    counts = recipes.countby(lambda r: r.upstream_status, results.values())
    bars = dicttoolz.valmap(lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts)
    for k in bars:
        print("%-20s %s (%d)" % (k.capitalize() if k else "No status", bars[k], counts[k]))
コード例 #3
0
def histogram(results):
    from toolz import recipes, dicttoolz
    import math
    counts = recipes.countby(lambda r: r.upstream_status, results.values())
    bars = dicttoolz.valmap(
        lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts)
    for k in bars:
        print("%-20s %s (%d)" %
              (k.capitalize() if k else "No status", bars[k], counts[k]))
コード例 #4
0
def active_servers_count(servers):
    """
    Return number of active servers based on their destiny.

    :param list servers: List of :obj:`NovaServer`

    :return: Number of servers as ``int``
    """
    counts = defaultdict(lambda: 0)
    counts.update(countby(get_destiny, servers))
    return (counts[Destiny.CONSIDER_AVAILABLE] +
            counts[Destiny.AVOID_REPLACING] +
            counts[Destiny.WAIT] +
            counts[Destiny.WAIT_WITH_TIMEOUT])