Commit ec871ead authored by Sergios Aftsidis's avatar Sergios Aftsidis

Add url mappings for rrd command dump

parent 30fb866a
......@@ -5,7 +5,7 @@ from mon_map.views import api
urlpatterns = patterns(
'',
url(r'^$', api.metro_map_json, name='metro-map'),
url(r'^links/(?P<from_node>[\w\d\-\.]+)/to/(?P<to_node>[\w\d\-\.]+)/$', api.link, name='link'),
url(r'^(?P<fake>f?)?links/(?P<from_node>[\w\d\-\.]+)/to/(?P<to_node>[\w\d\-\.]+)/$', api.link, name='link'),
url(r'^links/(?P<from_node>[\w\d\-\.]+)/to/(?P<to_node>[\w\d\-\.]+)/separate/$', api.link, {'separate': True}, name='link-separate'),
url(r'^load/(?P<from_node>[\w\d\-\.]+)/to/(?P<to_node>[\w\d\-\.]+)/$', api.link_load, name='load'),
url(r'^load/$', api.load, name='load-total'),
......
# -*- coding: utf-8 -*- vim:encoding=utf-8:
# -*- coding: utf-8 -*- vim:encoding=utf-8:
import json
from django.http import HttpResponse
from django.core.cache import cache
......@@ -93,10 +93,12 @@ def load(request):
return HttpResponse(result, content_type='application/json')
def link(request, from_node, to_node, separate=False):
def link(request, from_node, to_node, separate=False, fake=''):
start = request.GET.get('start', None)
end = request.GET.get('end', None)
dryrun = True if fake is not '' else False
links = []
links1 = Links.objects.filter(
......@@ -131,9 +133,9 @@ def link(request, from_node, to_node, separate=False):
datasources = [val for sublist in datasources for val in sublist]
if not separate:
if start and end:
url = create_graph_for_interfaces(datasources, start, end) or False
url = create_graph_for_interfaces(datasources, start, end, dryrun) or False
else:
url = create_graph_for_interfaces(datasources) or False
url = create_graph_for_interfaces(datasources, dryrun) or False
result = {'links': response, 'graph': url}
else:
if start and end:
......
......@@ -117,7 +117,7 @@ def graph_for_each_interface(datasources, start='-1d', end='-100'):
return response
def create_graph_for_interfaces(datasources, start=None, end=None):
def create_graph_for_interfaces(datasources, start=None, end=None, dryrun=False):
if not start:
start = '-1d'
if not end:
......@@ -176,7 +176,23 @@ def create_graph_for_interfaces(datasources, start=None, end=None):
legend.append('%s:aggr%s:%s:%s' % ('GPRINT', key, 'LAST', '\t%4.2lf%s\\n'))
arguments.extend(legend)
args = [str(val) for val in arguments]
rrdtool.graphv(*args)
if dryrun == True:
import re
for ri in range(len(args)):
if args[ri].find('-') == 0 and \
len(args[ri].split()) > 2:
larg = args[ri].split()
larg[1] = "'" + larg[1]
larg[-1] = larg[-1] + "'"
args[ri] = ' '.join(larg)
elif bool(re.search(r'^([CV]?DEF|AREA|GPRINT|COMMENT|HRULE):',
args[ri])):
args[ri] = "'%s'" % args[ri]
return ' \n'.join('rrdtool graph'.split() + args)
else:
rrdtool.graphv(*args)
url = reverse(
'get-png-data',
kwargs={
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment