예제 #1
0
파일: templates.py 프로젝트: Uninett/nav
def metric_path_for_cpu_load(sysname, cpu_name, interval):
    tmpl = "{cpu}.{cpu_name}.loadavg{interval}min"
    return tmpl.format(
        cpu=metric_prefix_for_cpu(sysname),
        cpu_name=escape_metric_name(cpu_name),
        interval=escape_metric_name(str(interval)),
    )
예제 #2
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
예제 #3
0
파일: templates.py 프로젝트: Uninett/nav
def metric_path_for_multicast_usage(group, sysname):
    tmpl = "{group}.igmp_usage.{sysname}"
    if hasattr(sysname, 'sysname'):
        sysname = sysname.sysname
    return tmpl.format(
        group=metric_prefix_for_multicast_group(group),
        sysname=escape_metric_name(sysname),
    )
예제 #4
0
def metric_prefix_for_multicast_group(group):
    tmpl = "nav.multicast.groups.{group}"
    return tmpl.format(group=escape_metric_name(six.text_type(group)))
예제 #5
0
def metric_prefix_for_prefix(netaddr):
    tmpl = "nav.prefixes.{netaddr}"
    if hasattr(netaddr, 'net_address'):
        netaddr = netaddr.net_address
    return tmpl.format(netaddr=escape_metric_name(netaddr))
예제 #6
0
def metric_prefix_for_memory(sysname, memory_name):
    tmpl = "{device}.memory.{memname}"
    return tmpl.format(device=metric_prefix_for_device(sysname),
                       memname=escape_metric_name(memory_name))
예제 #7
0
def metric_prefix_for_interface(sysname, ifname):
    tmpl = "{ports}.{ifname}"
    return tmpl.format(ports=metric_prefix_for_ports(sysname),
                       ifname=escape_metric_name(ifname))
예제 #8
0
def metric_prefix_for_device(sysname):
    tmpl = "nav.devices.{sysname}"
    if hasattr(sysname, 'sysname'):
        sysname = sysname.sysname
    return tmpl.format(sysname=escape_metric_name(sysname))
예제 #9
0
def metric_prefix_for_prefix(netaddr):
    tmpl = "nav.prefixes.{netaddr}"
    if hasattr(netaddr, 'net_address'):
        netaddr = netaddr.net_address
    return tmpl.format(netaddr=escape_metric_name(netaddr))
예제 #10
0
def metric_path_for_interface(sysname, ifname, counter):
    tmpl = "{interface}.{counter}"
    return tmpl.format(interface=metric_prefix_for_interface(sysname, ifname),
                       counter=escape_metric_name(counter))
예제 #11
0
def metric_path_for_sensor(sysname, sensor):
    tmpl = "{device}.sensors.{sensor}"
    return tmpl.format(device=metric_prefix_for_device(sysname),
                       sensor=escape_metric_name(sensor))
예제 #12
0
def metric_path_for_interface(sysname, ifname, counter):
    tmpl = "{interface}.{counter}"
    return tmpl.format(interface=metric_prefix_for_interface(sysname, ifname),
                       counter=escape_metric_name(counter))
예제 #13
0
def metric_path_for_prefix(netaddr, metric_name):
    tmpl = "{prefix}.{metric_name}"
    return tmpl.format(prefix=metric_prefix_for_prefix(netaddr),
                       metric_name=escape_metric_name(metric_name))
예제 #14
0
def metric_path_for_cpu_utilization(sysname, cpu_name):
    tmpl = "{cpu}.{cpu_name}.utilization"
    return tmpl.format(cpu=metric_prefix_for_cpu(sysname),
                       cpu_name=escape_metric_name(cpu_name))
예제 #15
0
def metric_path_for_cpu_load(sysname, cpu_name, interval):
    tmpl = "{cpu}.{cpu_name}.loadavg{interval}min"
    return tmpl.format(cpu=metric_prefix_for_cpu(sysname),
                       cpu_name=escape_metric_name(cpu_name),
                       interval=escape_metric_name(str(interval)))
예제 #16
0
def metric_prefix_for_ipdevpoll_job(sysname, job_name):
    tmpl = "{device}.ipdevpoll.{job_name}"
    return tmpl.format(device=metric_prefix_for_device(sysname),
                       job_name=escape_metric_name(job_name))
예제 #17
0
def metric_prefix_for_ipdevpoll_job(sysname, job_name):
    tmpl = "{device}.ipdevpoll.{job_name}"
    return tmpl.format(device=metric_prefix_for_device(sysname),
                       job_name=escape_metric_name(job_name))
예제 #18
0
def metric_path_for_sensor(sysname, sensor):
    tmpl = "{prefix}.{sensor}"
    return tmpl.format(prefix=metric_prefix_for_sensors(sysname),
                       sensor=escape_metric_name(sensor))
예제 #19
0
def metric_path_for_cpu_utilization(sysname, cpu_name):
    tmpl = "{cpu}.{cpu_name}.utilization"
    return tmpl.format(cpu=metric_prefix_for_cpu(sysname),
                       cpu_name=escape_metric_name(cpu_name))
예제 #20
0
def metric_prefix_for_interface(sysname, ifname):
    tmpl = "{ports}.{ifname}"
    return tmpl.format(ports=metric_prefix_for_ports(sysname),
                       ifname=escape_metric_name(ifname))
예제 #21
0
def metric_path_for_prefix(netaddr, metric_name):
    tmpl = "{prefix}.{metric_name}"
    return tmpl.format(prefix=metric_prefix_for_prefix(netaddr),
                       metric_name=escape_metric_name(metric_name))
예제 #22
0
def metric_prefix_for_memory(sysname, memory_name):
    tmpl = "{device}.memory.{memname}"
    return tmpl.format(device=metric_prefix_for_device(sysname),
                       memname=escape_metric_name(memory_name))
예제 #23
0
def test_escape_metric_name(test_input, expected):
    assert escape_metric_name(test_input) == expected
예제 #24
0
def metric_prefix_for_device(sysname):
    tmpl = "nav.devices.{sysname}"
    if hasattr(sysname, 'sysname'):
        sysname = sysname.sysname
    return tmpl.format(sysname=escape_metric_name(sysname))