mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Stats reactivated + New layout
This commit is contained in:
@@ -61,10 +61,10 @@ class Grapher(object):
|
||||
def process(self, target, suffix, start, end, tpl=traffic_avg_template):
|
||||
rrdfile = "%s/%s.rrd" % (self.rrd_rootdir, target)
|
||||
if not os.path.exists(rrdfile):
|
||||
print "[graph] no rrd file detected"
|
||||
print "[graph] no rrd file %s detected" %rrdfile
|
||||
return
|
||||
ext = "png"
|
||||
path = "%s/%s_%s_%s_%s.%s" % (self.img_rootdir, tpl['name'],
|
||||
path = "%s/%s_%s_%s_%s.%s" % (self.img_rootdir, tpl['name'],
|
||||
target, tpl['cf'], suffix, ext)
|
||||
start = str(start)
|
||||
end = str(end)
|
||||
@@ -74,7 +74,7 @@ class Grapher(object):
|
||||
defs += ['DEF:%s=%s:%s:%s' % (v, rrdfile, v, tpl['cf']),
|
||||
'CDEF:%spm=%s,60,*' % (v, v)]
|
||||
type = d.has_key("type") and d["type"] or "LINE"
|
||||
lines += ["%s:%spm%s:%s" % (type, v, d["color"],
|
||||
lines += ["%s:%spm%s:%s" % (type, v, d["color"],
|
||||
d["legend"].encode("utf-8"))]
|
||||
params = defs + lines
|
||||
rrdtool.graph(str(path),
|
||||
@@ -89,6 +89,11 @@ class Grapher(object):
|
||||
"--units-exponent", "0",
|
||||
*params)
|
||||
|
||||
if not os.path.exists(path):
|
||||
print "[graph] Impossible to create %s graph" %path
|
||||
else:
|
||||
print "[graph] %s graph created" %path
|
||||
|
||||
def make_defaults(self, target, tpl=traffic_avg_template):
|
||||
end = "%d" % int(time.mktime(time.localtime()))
|
||||
self.process(target, "day", "-1day", end, tpl)
|
||||
|
||||
@@ -5,7 +5,7 @@ import sys
|
||||
import os
|
||||
import re
|
||||
import rrdtool
|
||||
import string
|
||||
import string, pdb
|
||||
from optparse import OptionParser
|
||||
from mailng.lib import getoption
|
||||
from mailng.admin.models import Domain
|
||||
@@ -61,7 +61,8 @@ class LogParser(object):
|
||||
try:
|
||||
self.f = open(logfile)
|
||||
except IOError, errno:
|
||||
print "%s" % errno
|
||||
if self.debug:
|
||||
print "%s" % errno
|
||||
sys.exit(1)
|
||||
self.workdir = workdir
|
||||
self.year = year
|
||||
@@ -72,6 +73,8 @@ class LogParser(object):
|
||||
self.last_month = None
|
||||
if not self.year:
|
||||
self.year = time.localtime().tm_year
|
||||
if self.debug:
|
||||
print "[rrd] Dealing with year %s" %self.year
|
||||
self.data = {}
|
||||
domains = Domain.objects.all()
|
||||
self.domains = []
|
||||
@@ -134,7 +137,8 @@ class LogParser(object):
|
||||
m = t - (t % rrdstep)
|
||||
if not os.path.exists(fname):
|
||||
self.lupdates[fname] = self.init_rrd(fname, m)
|
||||
print "[rrd] create new RRD file"
|
||||
if self.debug:
|
||||
print "[rrd] create new RRD file %s" %fname
|
||||
else:
|
||||
if not self.lupdates.has_key(fname):
|
||||
self.lupdates[fname] = rrdtool.last(fname)
|
||||
@@ -227,10 +231,12 @@ class LogParser(object):
|
||||
m = re.search("to=<([^>]*)>.*status=(\S+)", line_log)
|
||||
if m:
|
||||
if not self.workdict.has_key(line_id):
|
||||
print "Inconsistent mail (%s: %s), skipping" % (line_id, m.group(1))
|
||||
if self.debug:
|
||||
print "Inconsistent mail (%s: %s), skipping" % (line_id, m.group(1))
|
||||
continue
|
||||
if not m.group(2) in variables:
|
||||
print "Unsupported status %s, skipping" % m.group(2)
|
||||
if self.debug:
|
||||
print "Unsupported status %s, skipping" % m.group(2)
|
||||
continue
|
||||
|
||||
addrfrom = re.match("([^@]+)@(.+)", self.workdict[line_id]['from'])
|
||||
@@ -258,6 +264,8 @@ class LogParser(object):
|
||||
# Sort everything by time
|
||||
G = grapher.Grapher()
|
||||
for dom, data in self.data.iteritems():
|
||||
if self.debug:
|
||||
print "[rrd] dealing with domain %s" %dom
|
||||
sortedData = {}
|
||||
sortedData = [ (i, data[i]) for i in sorted(data.keys()) ]
|
||||
for t, dict in sortedData:
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
{% extends "layout.html" %}
|
||||
{% extends "nlayout.html" %}
|
||||
{% load i18n %}
|
||||
{% load stats_extra %}
|
||||
{% block html_head %}
|
||||
<script src="/static/js/mootools-more.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/stylesheets/calendar.css" />
|
||||
<style type="text/css">
|
||||
#graphcontent {
|
||||
@@ -49,14 +48,14 @@ window.addEvent("domready", function() {
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% ifequal period "Custom" %}
|
||||
{% include "stats/calendar.html" %}
|
||||
{% if start or end %}
|
||||
<h3>{% trans "Custom period : from" %} {{ start }} {% trans "to" %} {{ end }}</h3>
|
||||
{% include "stats/graphs.html" %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% include "stats/graphs.html" %}
|
||||
{% include "stats/calendar.html" %}
|
||||
{% endifequal %}
|
||||
</div>
|
||||
{% if start or end %}
|
||||
<h3>{% trans "Custom period : from" %} {{ start }} {% trans "to" %} {{ end }}</h3>
|
||||
{% endif %}
|
||||
<div style="float:None;">
|
||||
{% include "stats/graphs.html" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
{% load i18n %}
|
||||
<div id="periodSelector" style="border:1px solid #dddddd;float:right;padding:3px;margin-top:-3px;">
|
||||
<div style="border:1px solid #dddddd;float:right;padding:3px;margin-top:-3px;">
|
||||
{% url extensions.stats.main.custom_period as c_stats_url %}
|
||||
<form class="calendarForm" action="{{ c_stats_url }}" method="POST">
|
||||
<!--<form class="calendarForm" onsubmit="change()">-->
|
||||
{% trans "Start" %}: <input id="dateTravelStart" name="start" value="{{ start }}" type="text"/>
|
||||
{% trans "End" %}: <input id="dateTravelEnd" name="end" value="{{ end }}" type="text" />
|
||||
<input TYPE=SUBMIT VALUE="ok">
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function change() {
|
||||
var dom_sel = $("domain").getElements("option.[selected]")[0].value;
|
||||
var per_sel = $("period").getElements("option.[selected]")[0].value;
|
||||
{% url extensions.stats.main.custom_period as c_stats_url %}
|
||||
location.href = "{{ c_stats_url }}" + "?period=" + per_sel + "&domain=" +
|
||||
dom_sel + "&start=" + $("dateTravelStart").value +
|
||||
"&end=" + $("dateTravelEnd").value;
|
||||
|
||||
};
|
||||
myCal = new Calendar(
|
||||
{
|
||||
dateTravelStart: 'D, Y/m/d',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "layout.html" %}
|
||||
{% extends "nlayout.html" %}
|
||||
{% block content %}
|
||||
{% load i18n %}
|
||||
<div id="body">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "layout.html" %}
|
||||
{% extends "nlayout.html" %}
|
||||
{% load i18n %}
|
||||
{% block html_head %}
|
||||
<script src="/static/js/calendar.js" type="text/javascript"></script>
|
||||
|
||||
Reference in New Issue
Block a user