Beispiel #1
0
def render_metric(request, metric, object_list):
    """
    Renders the total for the given metric.
    """
    # validate input
    form = GraphForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest()

    color = metric.graph_color
    if not color:
        color = '#990033'

    count = 0
    options = []
    type = 'AREA'
    for obj in object_list:
        data_file = metric.rrd_path(obj)
        if os.path.exists(data_file):
            options += [
                'DEF:%s=%s:%s:AVERAGE' % (count, data_file, metric.pk),
                '%s:%s%s' % (type, count, color)]
            type = 'STACK'
            count += 1

    # if no RRDs were found stop here
    if not count:
        raise Http404

    options += form.options()
    image_data = timegraph_rrd(options)

    return HttpResponse(image_data, content_type='image/png')
Beispiel #2
0
def render_metric(request, metric, object_list):
    """
    Renders the total for the given metric.
    """
    # validate input
    form = GraphForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest()

    color = metric.graph_color
    if not color:
        color = '#990033'

    count = 0
    options = []
    type = 'AREA'
    for obj in object_list:
        data_file = metric._rrd_path(obj)
        if os.path.exists(data_file):
            options += [
                'DEF:%s=%s:%s:AVERAGE' % (count, data_file, metric.pk),
                '%s:%s%s' % (type, count, color)]
            type = 'STACK'
            count += 1

    # if no RRDs were found stop here
    if not count:
        raise Http404

    options += form.options()
    image_data = timegraph_rrd(options)

    return HttpResponse(image_data, content_type='image/png')
Beispiel #3
0
def render_graph(request, graph, obj):
    """
    Renders the specified graph.
    """
    # validate input
    form = GraphForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest()

    count = 0
    options = []
    if graph.is_stacked:
        stack = ':STACK'
    else:
        stack = ''
    is_memory = False
    for metric in graph.metrics.order_by('graph_order'):
        if metric.unit in ['b', 'B']:
            is_memory = True
        data_file = metric.rrd_path(obj)
        value = metric.get_polling(obj)
        if os.path.exists(data_file):
            color = metric.graph_color
            if not color:
                color = COLORS[count % len(COLORS)]

            # current value
            value_str = format_value(value, metric.unit)
            if value_str:
                value_str = ' | ' + value_str

            options += [
                'DEF:%s=%s:%s:AVERAGE' % (count, data_file, metric.pk),
                '%s:%s%s:%s%s%s' % (graph.type, count, color, metric.name, value_str, stack)]
            count += 1

    # if no RRDs were found stop here
    if not count:
        raise Http404

    if is_memory:
        options += ['--base', '1024']
    if graph.lower_limit is not None:
        options += [ '--lower-limit', str(graph.lower_limit) ]
        options += [ '-r' ]
    if graph.upper_limit is not None:
        options += [ '--upper-limit', str(graph.upper_limit) ]
    options += form.options()
    image_data = timegraph_rrd(options)

    return HttpResponse(image_data, content_type='image/png')
Beispiel #4
0
def render_graph(request, graph, obj):
    """
    Renders the specified graph.
    """
    # validate input
    form = GraphForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest()

    count = 0
    options = []
    if graph.is_stacked:
        stack = ':STACK'
    else:
        stack = ''
    is_memory = False
    for metric in graph.metrics.order_by('graph_order'):
        if metric.unit in ['b', 'B']:
            is_memory = True
        data_file = metric._rrd_path(obj)
        value = metric.get_polling(obj)
        if os.path.exists(data_file):
            color = metric.graph_color
            if not color:
                color = COLORS[count % len(COLORS)]

            # current value
            value_str = format_value(value, metric.unit)
            if value_str:
                value_str = ' | ' + value_str

            options += [
                'DEF:%s=%s:%s:AVERAGE' % (count, data_file, metric.pk),
                '%s:%s%s:%s%s%s' % (graph.type, count, color, metric.name, value_str, stack)]
            count += 1

    # if no RRDs were found stop here
    if not count:
        raise Http404

    if is_memory:
        options += ['--base', '1024']
    if graph.lower_limit is not None:
        options += [ '--lower-limit', str(graph.lower_limit) ]
        options += [ '-r' ]
    if graph.upper_limit is not None:
        options += [ '--upper-limit', str(graph.upper_limit) ]
    options += form.options()
    image_data = timegraph_rrd(options)

    return HttpResponse(image_data, content_type='image/png')