statistics.html: Add gateway overview

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-01-10 22:49:01 +01:00
parent d567dfd56d
commit 34a7c4c58e
4 changed files with 89 additions and 3 deletions

View File

@ -116,6 +116,59 @@ def hoods_sum(mysql):
result[rs["hood"]] = {"routers": rs["count"], "clients": rs["clients"]}
return result
def gws(mysql,selecthood=None):
if selecthood:
where = " AND hood=%s"
tup = (selecthood,)
else:
where = ""
tup = ()
selected = mysql.fetchall("""
SELECT router_gw.mac, router.status, COUNT(router_gw.router) AS count
FROM router
INNER JOIN router_gw ON router.id = router_gw.router
WHERE router_gw.selected = TRUE {}
GROUP BY router_gw.mac, router.status
""".format(where),tup)
others = mysql.fetchall("""
SELECT router_gw.mac, router.status, COUNT(router_gw.router) AS count
FROM router
INNER JOIN router_gw ON router.id = router_gw.router
WHERE router_gw.selected = FALSE {}
GROUP BY router_gw.mac, router.status
""".format(where),tup)
result = {}
for rs in selected:
if not rs["mac"] in result:
result[rs["mac"]] = {"selected":{},"others":{}}
result[rs["mac"]]["selected"][rs["status"]] = rs["count"]
for rs in others:
if not rs["mac"] in result:
result[rs["mac"]] = {"selected":{},"others":{}}
result[rs["mac"]]["others"][rs["status"]] = rs["count"]
return result
def gws_sum(mysql,selecthood=None):
if selecthood:
where = " AND hood=%s"
tup = (selecthood,)
else:
where = ""
tup = ()
data = mysql.fetchall("""
SELECT router_gw.mac, COUNT(router_gw.router) AS count, SUM(router.clients) AS clients
FROM router
INNER JOIN router_gw ON router.id = router_gw.router
WHERE router_gw.selected = TRUE {}
GROUP BY router_gw.mac
""".format(where),tup)
result = {}
for rs in data:
result[rs["mac"]] = {"routers": rs["count"], "clients": rs["clients"]}
return result
def record_global_stats(mysql):
threshold=(utcnow() - datetime.timedelta(days=CONFIG["global_stat_days"])).timestamp()
time = mysql.utctimestamp()

View File

@ -364,6 +364,8 @@ def helper_statistics(mysql,stats,selecthood):
router_models = stattools.router_models(mysql,selecthood)
router_firmwares = stattools.router_firmwares(mysql,selecthood)
hoods_sum = stattools.hoods_sum(mysql)
gws = stattools.gws(mysql,selecthood)
gws_sum = stattools.gws_sum(mysql,selecthood)
mysql.close()
return render_template("statistics.html",
@ -375,7 +377,9 @@ def helper_statistics(mysql,stats,selecthood):
router_firmwares = router_firmwares,
hoods = hoods,
hoods_sum = hoods_sum,
newest_routers = newest_routers
newest_routers = newest_routers,
gws = gws,
gws_sum = gws_sum
)
@app.route('/register', methods=['GET', 'POST'])

View File

@ -34,6 +34,10 @@ def neighbour_color(quality):
color = "#79ff7c"
return color
@filters.app_template_filter('sumdict')
def sumdict(d):
return sum(d.values())
@filters.app_template_filter('utc2local')
def utc2local(dt):
return dt.astimezone(tz.tzlocal())

View File

@ -122,6 +122,33 @@
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Gateways (selected / others)</div>
<div class="panel-body">
<table class="table table-condensed table-hoods">
<tr>
<th class="firstrow">Gateway</th>
<th class="success" title="Online Routers">Online</th>
<th class="danger" title="Offline Routers">Offline</th>
<th class="warning" title="Unknown Routers">Unknown</th>
<th class="active" title="Total Routers">Total</th>
<th class="info">Clients</th>
</tr>
{%- for mac, value in gws|dictsort %}
<tr>
<td class="firstrow"><a href="{{ url_for('router_list', q='selected:^%s$' % mac) }}">{{ mac }}</a></td>
<td class="success"><span style="font-weight:bold">{{ value["selected"]["online"] or 0 }}</span> / {{ value["others"]["online"] or 0 }}</td>
<td class="danger"><span style="font-weight:bold">{{ value["selected"]["offline"] or 0 }}</span> / {{ value["others"]["offline"] or 0 }}</td>
<td class="warning"><span style="font-weight:bold">{{ value["selected"]["unknown"] or 0 }}</span> / {{ value["others"]["unknown"] or 0 }}</td>
<td class="active"><span style="font-weight:bold">{{ gws_sum[mac]["routers"] if gws_sum[mac] else 0 }}</span> / {{ value["others"]|sumdict if value["others"] else 0 }}</td>
<td class="info">{{ gws_sum[mac]["clients"] if gws_sum[mac] }}</td>
</tr>
{%- endfor %}
</table>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Router Firmwares{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
@ -129,8 +156,6 @@
<div id="globrouterfwstat" class="graph-pie"></div>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Router Models{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
<div class="panel-body">