Commit ec871ead authored by Sergios Aftsidis's avatar Sergios Aftsidis
Browse files

Add url mappings for rrd command dump

parent 30fb866a
...@@ -5,7 +5,7 @@ from mon_map.views import api ...@@ -5,7 +5,7 @@ from mon_map.views import api
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(r'^$', api.metro_map_json, name='metro-map'), 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'^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/(?P<from_node>[\w\d\-\.]+)/to/(?P<to_node>[\w\d\-\.]+)/$', api.link_load, name='load'),
url(r'^load/$', api.load, name='load-total'), url(r'^load/$', api.load, name='load-total'),
......
# -*- coding: utf-8 -*- vim:encoding=utf-8: # -*- coding: utf-8 -*- vim:encoding=utf-8:
import json import json
from django.http import HttpResponse from django.http import HttpResponse
from django.core.cache import cache from django.core.cache import cache
...@@ -93,10 +93,12 @@ def load(request): ...@@ -93,10 +93,12 @@ def load(request):
return HttpResponse(result, content_type='application/json') 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) start = request.GET.get('start', None)
end = request.GET.get('end', None) end = request.GET.get('end', None)
dryrun = True if fake is not '' else False
links = [] links = []
links1 = Links.objects.filter( links1 = Links.objects.filter(
...@@ -131,9 +133,9 @@ def link(request, from_node, to_node, separate=False): ...@@ -131,9 +133,9 @@ def link(request, from_node, to_node, separate=False):
datasources = [val for sublist in datasources for val in sublist] datasources = [val for sublist in datasources for val in sublist]
if not separate: if not separate:
if start and end: 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: else:
url = create_graph_for_interfaces(datasources) or False url = create_graph_for_interfaces(datasources, dryrun) or False
result = {'links': response, 'graph': url} result = {'links': response, 'graph': url}
else: else:
if start and end: if start and end:
......
...@@ -117,7 +117,7 @@ def graph_for_each_interface(datasources, start='-1d', end='-100'): ...@@ -117,7 +117,7 @@ def graph_for_each_interface(datasources, start='-1d', end='-100'):
return response 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: if not start:
start = '-1d' start = '-1d'
if not end: if not end:
...@@ -176,7 +176,23 @@ def create_graph_for_interfaces(datasources, start=None, end=None): ...@@ -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')) legend.append('%s:aggr%s:%s:%s' % ('GPRINT', key, 'LAST', '\t%4.2lf%s\\n'))
arguments.extend(legend) arguments.extend(legend)
args = [str(val) for val in arguments] 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( url = reverse(
'get-png-data', 'get-png-data',
kwargs={ 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