Skip to content

Commit

Permalink
jqPlot graphs generation simplification (less JS generated by templates)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaikali committed Sep 8, 2012
1 parent 001865d commit 5d72080
Show file tree
Hide file tree
Showing 15 changed files with 1,155 additions and 518 deletions.
702 changes: 674 additions & 28 deletions LICENSE

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions skwissh/cron.py
Expand Up @@ -110,10 +110,7 @@ def storeValue(server, probe, timestamp, server_up):
success = False

if not success:
if probe.graph_type.name == 'text':
output = "No data"
else:
output = "0"
output = "No data" if probe.graph_type.name == 'text' else "0"

if probe.graph_type.name == 'text':
Measure.objects.filter(server=server, probe=probe).delete()
Expand Down Expand Up @@ -161,7 +158,7 @@ def calculateAverage(period, classname):
for server in Server.objects.all().select_related():
try:
threads = []
for probe in server.probes.filter(graph_type__name__in=['linegraph', 'bargraph', 'pie']):
for probe in server.probes.exclude(graph_type__name__in=['text']):
thread = threading.Thread(target=calculateAveragesForPeriod, args=[period, classname, server, probe], name="SkwisshAverage.%s.%s" % (classname.__name__, probe.display_name.encode('utf-8').replace(" ", "_")))
thread.setDaemon(False)
thread.start()
Expand Down
2 changes: 1 addition & 1 deletion skwissh/fields.py
Expand Up @@ -27,7 +27,7 @@ def get_db_prep_value(self, value, connection, prepared=False):
if value is not None and not isinstance(value, EncryptedString):
padding = self.cipher.block_size - len(value) % self.cipher.block_size
if padding and padding < self.cipher.block_size:
value += "\0" + ''.join([random.choice(string.printable) for i in range(padding - 1)])
value += "\0" + ''.join([random.choice(string.printable) for i in range(padding - 1)]) # @UnusedVariable 'i'
value = EncryptedString(binascii.b2a_hex(self.cipher.encrypt(value)))
return value

Expand Down
72 changes: 36 additions & 36 deletions skwissh/fixtures/initial_data.json
Expand Up @@ -4,42 +4,42 @@
"model": "skwissh.graphtype",
"fields": {
"date_created": "2012-05-20T10:07:47Z",
"date_modified": "2012-08-31T13:31:29.488Z",
"date_modified": "2012-09-08T14:29:10Z",
"name": "bargraph",
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\naxes: {\r\n xaxis: {\r\n renderer: $.jqplot.DateAxisRenderer,\r\n min: minDate,\r\n max: maxDate,\r\n tickInterval: tickInt,\r\n tickOptions: {\r\n formatString: \"<center>%R<br/>%d %b</center>\",\r\n },\r\n },\r\n yaxis: {\r\n min:0,\r\n autoscale: true,\r\n tickOptions: {\r\n formatString: \"<center>%.2f @UNITS@</center>\",\r\n },\r\n },\r\n},\r\nseriesDefaults: {\r\n renderer:$.jqplot.BarRenderer,\r\n shadow: false,\r\n showMarker: false,\r\n rendererOptions: {\r\n barMargin: bMgin,\r\n },\r\n markerOptions: {\r\n show: false,\r\n size: 0,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showLabel: true, \r\n sizeAdjust: 1,\r\n tooltipLocation : 'n',\r\n useAxesFormatters: true,\r\n tooltipAxes: 'both',\r\n tooltipSeparator: '',\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},\r\ncursor: { \r\n zoom: true, \r\n style: 'default',\r\n show: true,\r\n constrainZoomTo: 'x',\r\n constrainOutsideZoom: true,\r\n showTooltip: false,\r\n},\r\n@SERIES@,\r\nanimate: true,\r\nanimateReplot: false,\r\nstackSeries: true,"
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\naxes: {\r\n xaxis: {\r\n renderer: $.jqplot.DateAxisRenderer,\r\n tickOptions: {\r\n formatString: \"<center>%R<br/>%d %b</center>\",\r\n },\r\n },\r\n yaxis: {\r\n min:0,\r\n autoscale: true,\r\n tickOptions: {\r\n formatString: \"<center>%.2f @UNITS@</center>\",\r\n },\r\n },\r\n},\r\nseriesDefaults: {\r\n renderer:$.jqplot.BarRenderer,\r\n shadow: false,\r\n showMarker: false,\r\n markerOptions: {\r\n show: false,\r\n size: 0,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showLabel: true, \r\n sizeAdjust: 1,\r\n tooltipLocation : 'n',\r\n useAxesFormatters: true,\r\n tooltipAxes: 'both',\r\n tooltipSeparator: '',\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},\r\ncursor: { \r\n zoom: true, \r\n style: 'default',\r\n show: true,\r\n constrainZoomTo: 'x',\r\n constrainOutsideZoom: true,\r\n showTooltip: false,\r\n},\r\nanimate: true,\r\nanimateReplot: false,\r\nstackSeries: true,"
}
}, {
"pk": 1,
"model": "skwissh.graphtype",
"fields": {
"date_created": "2012-05-17T18:01:01Z",
"date_modified": "2012-08-30T16:55:11.368Z",
"date_modified": "2012-09-08T14:29:21Z",
"name": "linegraph",
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\naxes: {\r\n xaxis: {\r\n renderer: $.jqplot.DateAxisRenderer,\r\n min: minDate,\r\n max: maxDate,\r\n tickInterval: tickInt,\r\n tickOptions: {\r\n formatString: \"<center>%R<br/>%d %b</center>\",\r\n },\r\n },\r\n yaxis: {\r\n min:0,\r\n autoscale: true,\r\n tickOptions: {\r\n formatString: \"<center>%.2f @UNITS@</center>\",\r\n },\r\n },\r\n},\r\nseriesDefaults: {\r\n lineWidth:2,\r\n shadow: false,\r\n markerOptions: {\r\n show: false,\r\n },\r\n rendererOptions: {\r\n smooth: true,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showLabel: true, \r\n sizeAdjust: 1,\r\n tooltipLocation : 'n',\r\n useAxesFormatters: true,\r\n tooltipAxes: 'both',\r\n tooltipSeparator: '',\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},\r\ncursor: { \r\n zoom: true, \r\n style: 'default',\r\n show: true,\r\n constrainZoomTo: 'x',\r\n constrainOutsideZoom: true,\r\n showTooltip: false,\r\n},\r\n@SERIES@,\r\nanimate: true,\r\nanimateReplot: false,"
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\naxes: {\r\n xaxis: {\r\n renderer: $.jqplot.DateAxisRenderer,\r\n tickOptions: {\r\n formatString: \"<center>%R<br/>%d %b</center>\",\r\n },\r\n },\r\n yaxis: {\r\n min:0,\r\n autoscale: true,\r\n tickOptions: {\r\n formatString: \"<center>%.2f @UNITS@</center>\",\r\n },\r\n },\r\n},\r\nseriesDefaults: {\r\n lineWidth:2,\r\n shadow: false,\r\n markerOptions: {\r\n show: false,\r\n },\r\n rendererOptions: {\r\n smooth: true,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showLabel: true, \r\n sizeAdjust: 1,\r\n tooltipLocation : 'n',\r\n useAxesFormatters: true,\r\n tooltipAxes: 'both',\r\n tooltipSeparator: '',\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},\r\ncursor: { \r\n zoom: true, \r\n style: 'default',\r\n show: true,\r\n constrainZoomTo: 'x',\r\n constrainOutsideZoom: true,\r\n showTooltip: false,\r\n},\r\nanimate: true,\r\nanimateReplot: false,"
}
}, {
"pk": 2,
"model": "skwissh.graphtype",
"fields": {
"date_created": "2012-05-17T18:06:27Z",
"date_modified": "2012-08-31T09:04:44.235Z",
"date_modified": "2012-09-08T14:27:50Z",
"name": "pie",
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\nseriesDefaults: {\r\n renderer: jQuery.jqplot.PieRenderer, \r\n shadow: false,\r\n rendererOptions: {\r\n showDataLabels: true,\r\n sliceMargin: 3,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showTooltip: false,\r\n},\r\ncursor: {\r\n show: false,\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},\r\n@SERIES@,"
"options": "seriesColors: [ \"#7FAE00\", \"#EAA228\", \"#D5383B\", \"#4EA5B5\" ],\r\nseriesDefaults: {\r\n renderer: jQuery.jqplot.PieRenderer, \r\n shadow: false,\r\n rendererOptions: {\r\n showDataLabels: true,\r\n sliceMargin: 3,\r\n },\r\n},\r\nhighlighter: {\r\n show: true, \r\n showTooltip: false,\r\n},\r\ncursor: {\r\n show: false,\r\n},\r\ngrid: {\r\n background: '#F2F2F2',\r\n},"
}
}, {
"pk": 3,
"model": "skwissh.graphtype",
"fields": {
"date_created": "2012-05-20T10:07:47Z",
"date_modified": "2012-08-30T11:33:24.279Z",
"date_modified": "2012-08-30T11:33:24Z",
"name": "text",
"options": ""
}
}, {
"pk": 3,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-31T12:08:16.877Z",
"date_modified": "2012-08-31T12:08:16Z",
"addon_name": "",
"display_name": "CPU (Usage)",
"ssh_command": "top -d0.2 -bn2 | grep \"Cpu\"",
Expand All @@ -54,7 +54,7 @@
"pk": 6,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-29T10:11:26.369Z",
"date_modified": "2012-08-29T10:11:26Z",
"addon_name": "",
"display_name": "CPU (Wait IO)",
"ssh_command": "top -d0.2 -bn2 | grep \"Cpu\"",
Expand All @@ -69,7 +69,7 @@
"pk": 4,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-29T12:32:18.372Z",
"date_modified": "2012-08-29T12:32:18Z",
"addon_name": "Ubuntu 12.04",
"display_name": "Disk Usage",
"ssh_command": "df -h / | tail -1",
Expand All @@ -84,7 +84,7 @@
"pk": 2,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-29T10:08:49.029Z",
"date_modified": "2012-08-29T10:08:49Z",
"addon_name": "",
"display_name": "Load",
"ssh_command": "cat /proc/loadavg",
Expand All @@ -99,37 +99,22 @@
"pk": 8,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-30T07:48:32.459Z",
"date_modified": "2012-08-30T07:48:32Z",
"addon_name": "",
"display_name": "Memory",
"ssh_command": "cat /proc/meminfo",
"probe_labels": "Free memory;Buffers;Used memory",
"use_sudo": false,
"probe_unit": "Mo",
"date_created": "2012-08-29T08:20:23.631Z",
"date_created": "2012-08-29T08:20:23Z",
"graph_type": 4,
"python_parse": "meminfos = dict([(info.split(':')[0].strip(), int(info.split()[1].strip())/1024) for info in output.splitlines()])\r\noutput = \";\".join([str(meminfos['MemFree']), str(meminfos['Buffers']), str(meminfos['MemTotal'] - meminfos['MemFree'] - meminfos['Buffers'])])"
}
}, {
"pk": 9,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-30T09:17:37.221Z",
"addon_name": "",
"display_name": "Memory (Swap)",
"ssh_command": "cat /proc/meminfo",
"probe_labels": "Free swap;Used swap",
"use_sudo": false,
"probe_unit": "Mo",
"date_created": "2012-08-29T08:42:29.645Z",
"graph_type": 4,
"python_parse": "meminfos = dict([(info.split(':')[0].strip(), int(info.split()[1].strip()) / 1024) for info in output.splitlines()])\r\noutput = \";\".join([str(meminfos['SwapFree']), str(meminfos['SwapTotal'] - meminfos['SwapFree'])])"
}
}, {
"pk": 7,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-31T09:02:39.186Z",
"date_modified": "2012-08-31T09:02:39Z",
"addon_name": "",
"display_name": "Memory (pie)",
"ssh_command": "cat /proc/meminfo",
Expand All @@ -140,33 +125,48 @@
"graph_type": 2,
"python_parse": "meminfos = dict([(info.split(':')[0].strip(), int(info.split()[1].strip())) for info in output.splitlines()])\r\noutput = \";\".join([str(meminfos['MemFree']), str(meminfos['Buffers']), str(meminfos['MemTotal'] - meminfos['MemFree'] - meminfos['Buffers'])])"
}
}, {
"pk": 9,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-30T09:17:37Z",
"addon_name": "",
"display_name": "Memory (Swap)",
"ssh_command": "cat /proc/meminfo",
"probe_labels": "Free swap;Used swap",
"use_sudo": false,
"probe_unit": "Mo",
"date_created": "2012-08-29T08:42:29Z",
"graph_type": 4,
"python_parse": "meminfos = dict([(info.split(':')[0].strip(), int(info.split()[1].strip()) / 1024) for info in output.splitlines()])\r\noutput = \";\".join([str(meminfos['SwapFree']), str(meminfos['SwapTotal'] - meminfos['SwapFree'])])"
}
}, {
"pk": 11,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-31T13:04:55.729Z",
"date_modified": "2012-08-31T13:04:55Z",
"addon_name": "",
"display_name": "Network data",
"ssh_command": "nstat | grep \"IpExt\"",
"probe_labels": "Received;Sent",
"use_sudo": false,
"probe_unit": "Ko",
"date_created": "2012-08-29T11:26:06.849Z",
"date_created": "2012-08-29T11:26:06Z",
"graph_type": 4,
"python_parse": "bdwth = dict([(info.split()[0].strip(), int(info.split()[1].strip()) / 1024) for info in output.splitlines()])\r\noutput = \";\".join([str(bdwth['IpExtInOctets']), str(bdwth['IpExtOutOctets'])])"
}
}, {
"pk": 10,
"model": "skwissh.probe",
"fields": {
"date_modified": "2012-08-29T10:04:52.393Z",
"date_modified": "2012-08-29T10:04:52Z",
"addon_name": "",
"display_name": "System idle time",
"ssh_command": "cat /proc/uptime",
"probe_labels": "Idle;Working",
"use_sudo": false,
"probe_unit": "",
"date_created": "2012-08-29T09:59:16.827Z",
"date_created": "2012-08-29T09:59:16Z",
"graph_type": 2,
"python_parse": "uptime = output.strip().split()\r\nuptime.reverse()\r\noutput = \";\".join(uptime)"
}
Expand All @@ -191,13 +191,13 @@
"fields": {
"username": "",
"is_measuring": false,
"date_modified": "2012-08-31T16:18:07.893Z",
"date_modified": "2012-09-08T16:01:03Z",
"ip": "127.0.0.1",
"hostname": "localhost",
"hostname": "Django Skwissh webserver",
"state": true,
"date_created": "2012-08-19T18:57:21Z",
"password": "",
"probes": [3, 6, 4, 2, 8, 9, 7, 11, 10, 5]
"probes": [3, 6, 4, 2, 8, 7, 9, 11, 10, 5]
}
}
]
53 changes: 30 additions & 23 deletions skwissh/generic_views.py
Expand Up @@ -20,12 +20,8 @@ def get_success_url(self):

def get_context_data(self, **kwargs):
context = super(AddServerView, self).get_context_data(**kwargs)
ServerGroupFormSet = modelformset_factory(ServerGroup, form=ServerGroupForm)
context.update(get_server_list_context_data())
context['server_form'] = context['form']
context['server_group_form'] = ServerGroupForm()
context['server_group_formset'] = ServerGroupFormSet(queryset=ServerGroup.objects.all().select_related())
context['groups'] = ServerGroup.objects.all().order_by('name')
context['nogroup_servers'] = Server.objects.filter(servergroup__isnull=True).order_by('hostname')
return context


Expand Down Expand Up @@ -55,12 +51,8 @@ def get_success_url(self):

def get_context_data(self, **kwargs):
context = super(AddServerGroupView, self).get_context_data(**kwargs)
ServerGroupFormSet = modelformset_factory(ServerGroup, form=ServerGroupForm)
context['server_form'] = ServerForm()
context.update(get_server_list_context_data())
context['server_group_form'] = context['form']
context['server_group_formset'] = ServerGroupFormSet(queryset=ServerGroup.objects.all().select_related())
context['groups'] = ServerGroup.objects.all().order_by('name')
context['nogroup_servers'] = Server.objects.filter(servergroup__isnull=True).order_by('hostname')
return context


Expand All @@ -72,11 +64,8 @@ class UpdateServerGroupView(ModelFormSetView):

def get_context_data(self, **kwargs):
context = super(UpdateServerGroupView, self).get_context_data(**kwargs)
context['server_form'] = ServerForm()
context['server_group_form'] = ServerGroupForm()
context.update(get_server_list_context_data())
context['server_group_formset'] = context['formset']
context['groups'] = ServerGroup.objects.all().order_by('name')
context['nogroup_servers'] = Server.objects.filter(servergroup__isnull=True).order_by('hostname')
return context


Expand All @@ -100,12 +89,8 @@ def get_success_url(self):

def get_context_data(self, **kwargs):
context = super(AddProbeView, self).get_context_data(**kwargs)
ProbeFormSet = modelformset_factory(Probe, form=ProbeForm)
context.update(get_probe_list_context_data())
context['probe_form'] = context['form']
context['probe_formset'] = ProbeFormSet(queryset=Probe.objects.all().select_related())
context['probes'] = Probe.objects.all()
context['groups'] = ServerGroup.objects.all().order_by('name')
context['nogroup_servers'] = Server.objects.filter(servergroup__isnull=True).order_by('hostname')
return context


Expand All @@ -117,11 +102,8 @@ class UpdateProbeView(ModelFormSetView):

def get_context_data(self, **kwargs):
context = super(UpdateProbeView, self).get_context_data(**kwargs)
context['probe_form'] = ProbeForm()
context.update(get_probe_list_context_data())
context['probe_formset'] = context['formset']
context['probes'] = Probe.objects.all()
context['groups'] = ServerGroup.objects.all().order_by('name')
context['nogroup_servers'] = Server.objects.filter(servergroup__isnull=True).order_by('hostname')
return context


Expand All @@ -130,3 +112,28 @@ class DeleteProbeView(DeleteView):

def get_success_url(self):
return reverse_lazy('probe-list')


#------------------------------------------------------------------------------
# Context data
#------------------------------------------------------------------------------
def get_server_list_context_data():
ServerGroupFormSet = modelformset_factory(ServerGroup, form=ServerGroupForm)
return {
'server_form': ServerForm(),
'server_group_form': ServerGroupForm(),
'server_group_formset': ServerGroupFormSet(queryset=ServerGroup.objects.all().select_related()),
'groups': ServerGroup.objects.all().order_by('name'),
'nogroup_servers': Server.objects.filter(servergroup__isnull=True).order_by('hostname'),
}


def get_probe_list_context_data():
ProbeFormSet = modelformset_factory(Probe, form=ProbeForm)
return {
'probe_form': ProbeForm(),
'probe_formset': ProbeFormSet(queryset=Probe.objects.all().select_related()),
'probes': Probe.objects.all(),
'groups': ServerGroup.objects.all().order_by('name'),
'nogroup_servers': Server.objects.filter(servergroup__isnull=True).order_by('hostname')
}
Binary file modified skwissh/locale/en/LC_MESSAGES/django.mo
Binary file not shown.

0 comments on commit 5d72080

Please sign in to comment.