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)), )
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
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), )
def metric_prefix_for_multicast_group(group): tmpl = "nav.multicast.groups.{group}" return tmpl.format(group=escape_metric_name(six.text_type(group)))
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))
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))
def metric_prefix_for_interface(sysname, ifname): tmpl = "{ports}.{ifname}" return tmpl.format(ports=metric_prefix_for_ports(sysname), ifname=escape_metric_name(ifname))
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))
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))
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))
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))
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))
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)))
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))
def metric_path_for_sensor(sysname, sensor): tmpl = "{prefix}.{sensor}" return tmpl.format(prefix=metric_prefix_for_sensors(sysname), sensor=escape_metric_name(sensor))
def test_escape_metric_name(test_input, expected): assert escape_metric_name(test_input) == expected