diff --git a/modoboa/extensions/stats/graph_templates.py b/modoboa/extensions/stats/graph_templates.py new file mode 100644 index 000000000..ce629c822 --- /dev/null +++ b/modoboa/extensions/stats/graph_templates.py @@ -0,0 +1,51 @@ +# coding: utf-8 + +from django.utils.translation import ugettext_lazy + +class MailTrafic(object): + pass + +traffic_avg_template = { + 'name' : 'traffic', + 'title' : ugettext_lazy("Average normal traffic"), + 'width' : '540', + 'height' : '120', + 'vertlabel' : ugettext_lazy('msgs/min'), + 'cf' : 'AVERAGE', + 'vars' : { + 'sent' : { "type" : "AREA", "color" : "#00FF00", + "legend" : ugettext_lazy("sent messages") }, + 'recv' : { "type" : "AREA", "color" : "#0000FF", + "legend" : ugettext_lazy("received messages") }, + } +} + +badtraffic_avg_template = { + 'name' : 'badtraffic', + 'title' : ugettext_lazy("Average bad traffic"), + 'width' : '540', + 'height' : '120', + 'vertlabel' : ugettext_lazy('msgs/min'), + 'cf' : 'AVERAGE', + 'vars' : { + 'bounced' : { "type" : "AREA", "color" : "#FFFF00", + "legend" : ugettext_lazy("bounced messages") }, + 'reject' : { "type" : "AREA", "color" : "#FF0000", + "legend" : ugettext_lazy("rejected messages") }, + } +} + +size_avg_template = { + 'name' : 'size', + 'title' : ugettext_lazy("Average normal traffic size"), + 'width' : '540', + 'height' : '120', + 'vertlabel' : ugettext_lazy('bytes/min'), + 'cf' : 'AVERAGE', + 'vars' : { + 'size_recv' : { "type" : "AREA", "color" : "#FF9900", + "legend" : ugettext_lazy("received size") }, + 'size_sent' : { "type" : "AREA", "color" : "#339999", + "legend" : ugettext_lazy("sent size") }, + } +} diff --git a/modoboa/extensions/stats/grapher.py b/modoboa/extensions/stats/grapher.py index 8d8f3f10f..4da6ac8e4 100644 --- a/modoboa/extensions/stats/grapher.py +++ b/modoboa/extensions/stats/grapher.py @@ -1,57 +1,11 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 import sys, os import time import datetime -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_lazy from modoboa.lib import parameters -traffic_avg_template = { - 'name' : 'traffic', - 'width' : '540', - 'height' : '100', - 'vertlabel' : 'msgs/min', - 'cf' : 'AVERAGE', - 'vars' : { - 'sent' : { "type" : "AREA", "color" : "#00FF00", - "legend" : _("sent messages") }, - 'recv' : { "type" : "AREA", "color" : "#0000FF", - "legend" : _("received messages") }, - } -} - -badtraffic_avg_template = { - 'name' : 'badtraffic', - 'width' : '540', - 'height' : '100', - 'vertlabel' : _('msgs/min'), - 'cf' : 'AVERAGE', - 'vars' : { - 'bounced' : { "type" : "AREA", "color" : "#FFFF00", - "legend" : _("bounced messages") }, - 'reject' : { "type" : "AREA", "color" : "#FF0000", - "legend" : _("rejected messages") }, - } -} - -size_avg_template = { - 'name' : 'size', - 'width' : '540', - 'height' : '100', - 'vertlabel' : _('bytes/min'), - 'cf' : 'AVERAGE', - 'vars' : { - 'size_recv' : { "type" : "AREA", "color" : "#FF9900", - "legend" : _("received size") }, - 'size_sent' : { "type" : "AREA", "color" : "#339999", - "legend" : _("sent size") }, - } -} - -tpl = {'traffic':traffic_avg_template, - 'badtraffic':badtraffic_avg_template, - 'size':size_avg_template} - def str2Time(y, M, d, h="0", m="0", s="0"): """Date conversion @@ -77,7 +31,7 @@ class Grapher(object): self.rrd_rootdir = parameters.get_admin("RRD_ROOTDIR") self.img_rootdir = parameters.get_admin("IMG_ROOTDIR") - def process(self, target, suffix, start, end, tpl=traffic_avg_template): + def process(self, target, suffix, start, end, tpl): import rrdtool rrdfile = "%s/%s.rrd" % (self.rrd_rootdir, target) @@ -90,12 +44,17 @@ class Grapher(object): end = str(end) defs = [] lines = [] + defs.append('COMMENT: %s %s %s %s\\c' % ("From", start, "to", end)) + defs.append('COMMENT:\\s') for v, d in tpl["vars"].iteritems(): defs += [str('DEF:%s=%s:%s:%s' % (v, rrdfile, v, tpl['cf'])), - str('CDEF:%spm=%s,60,*' % (v, v))] + str('CDEF:%spm=%s,60,*' % (v, v)), + str('VDEF:%s_total=%s,TOTAL' % (v, v))] type = d.has_key("type") and d["type"] or "LINE" - lines += [str("%s:%spm%s:%s" % (type, v, d["color"], - d["legend"].encode("utf-8")))] + lines += [str("%s:%spm%s:%s:STACK" % (type, v, d["color"], + (d["legend"].encode("utf8")).ljust(20)))] + lines.append('GPRINT:%s_total:%s%%7.0lf%%s\\l' % (v, _("Total").encode('utf-8'))) + params = defs + lines rrdtool.graph(str(path), "--imgformat", "PNG", @@ -107,12 +66,13 @@ class Grapher(object): "--lower-limit", "0", "--slope-mode", "--units-exponent", "0", + "--title", tpl["title"].encode("utf-8"), *params) if not os.path.exists(path): print "[graph] Impossible to create %s graph" %path - def make_defaults(self, target, tpl=traffic_avg_template): + def make_defaults(self, target, tpl): end = "%d" % int(time.mktime(time.localtime())) self.process(target, "day", "-1day", end, tpl) self.process(target, "week", "-1week", end, tpl) diff --git a/modoboa/extensions/stats/static/stats/css/stats.css b/modoboa/extensions/stats/static/stats/css/stats.css index 71e70d3e6..e69de29bb 100644 --- a/modoboa/extensions/stats/static/stats/css/stats.css +++ b/modoboa/extensions/stats/static/stats/css/stats.css @@ -1,24 +0,0 @@ -#fixed_content { - padding: 0 15px; -} - -#searchform { - float: left; - margin-right: 10px; - margin-bottom: 0px; -} - -#menubar { - clear: both; -} - -#graphs { - margin-top: 15px; -} - -#period { -} - -#custom-period { - margin-left: 10px; -} \ No newline at end of file diff --git a/modoboa/extensions/stats/static/stats/js/stats.js b/modoboa/extensions/stats/static/stats/js/stats.js index 1460b5fc1..d371966cf 100644 --- a/modoboa/extensions/stats/static/stats/js/stats.js +++ b/modoboa/extensions/stats/static/stats/js/stats.js @@ -31,14 +31,6 @@ Stats.prototype = { } } }); - if (navobj.params.period) { - $("input[value=" + navobj.params.period + "]").attr("checked", "checked"); - if (navobj.params.period != "custom") { - $("#custom-period").hide(); - } - } else { - $("#custom-period").hide(); - } if (navobj.params.start) { $("#id_from").attr("value", navobj.params.start); } @@ -55,8 +47,7 @@ Stats.prototype = { listen: function() { $("#searchform").on("keypress", $.proxy(this.search_domain, this)); - $(document).on("change", "input[name=period]", - $.proxy(this.change_period, this)); + $(".period_selector").click($.proxy(this.change_period, this)); $("#customsend").on("click", $.proxy(this.customgraphs, this)); }, @@ -66,15 +57,11 @@ Stats.prototype = { }, change_period: function(e) { - var $input = $(e.target); + e.preventDefault(); + var $link = $(e.target); - if ($input.attr("value") == "custom") { - $("#custom-period").show(); - } else { - $("#custom-period").hide(); - this.navobj.delparam("start").delparam("end"); - this.navobj.setparam("period", $input.attr("value")).update(); - } + this.navobj.delparam("start").delparam("end"); + this.navobj.setparam("period", $link.attr("data-period")).update(); }, graphs_cb: function(data) { @@ -82,7 +69,7 @@ Stats.prototype = { $("body").notify("error", data.respmsg); return; } - $("#graphs").html(data.content); + $("#graphs_mailstats").html(data.content); }, search_domain: function(e) { diff --git a/modoboa/extensions/stats/templates/stats/graphs.html b/modoboa/extensions/stats/templates/stats/graphs.html index 83a088259..114deb675 100644 --- a/modoboa/extensions/stats/templates/stats/graphs.html +++ b/modoboa/extensions/stats/templates/stats/graphs.html @@ -1,9 +1,5 @@ {% load i18n %} -{% if start or end %} -

