예제 #1
0
파일: db.py 프로젝트: plan1230/nav
def get_multiple_cpu_load(items, time_interval):
    """
    Gets the CPU load of netboxes, averaged over a time interval, and adds to
    the load properties of the items.

    :param items: A dictionary of {sysname: properties lazy_dict, ...}
    :param time_interval: A dict(start=..., end=...) describing the desired
                          time interval in terms valid to Graphite web.
    """
    target_map = {
        escape_metric_name(sysname): netbox
        for sysname, netbox in iteritems(items)
    }
    targets = []
    for sysname, netbox in iteritems(items):
        if not sysname:
            continue

        targets.extend([
            'highestMax(%s,1)' % path
            for path in (metric_path_for_cpu_load(sysname, '*', interval=5),
                         metric_path_for_cpu_utilization(sysname, '*'))
        ])

    _logger.debug("getting %s graphite cpu targets in chunks", len(targets))
    data = {}
    for chunk in chunks(targets, METRIC_CHUNK_SIZE):
        data.update(_get_metric_average(chunk, time_interval))

    for key, value in iteritems(data):
        for sysname, netbox in iteritems(target_map):
            if sysname in key:
                if not is_nan(value):
                    netbox['load'] = value
                    break
예제 #2
0
파일: geomap.py 프로젝트: snauman817/nav
def filter_nan2none(value):
    """Convert the NaN value to None, leaving everything else unchanged.

    This function is meant to be used as a Django template filter. It
    is useful in combination with filters that handle None (or any
    false value) specially, such as the 'default' filter, when one
    wants special treatment for the NaN value. It is also useful
    before the 'format' filter to avoid the NaN value being formatted.

    """
    if is_nan(value):
        return None
    return value