mirror of
https://github.com/FreifunkFranken/fff-monitoring.git
synced 2024-06-16 20:34:02 +02:00
router.html/statistics.html: Display gateway/batX where available
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
1d64dc3e25
commit
669895cd7b
|
@ -7,7 +7,7 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
||||||
from ffmap.mysqltools import FreifunkMySQL
|
from ffmap.mysqltools import FreifunkMySQL
|
||||||
from ffmap.misc import *
|
from ffmap.misc import *
|
||||||
from ffmap.config import CONFIG
|
from ffmap.config import CONFIG
|
||||||
from flask import request
|
from flask import request, url_for
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
@ -62,3 +62,17 @@ def import_gw_data(mysql, gw_data):
|
||||||
""",adata)
|
""",adata)
|
||||||
else:
|
else:
|
||||||
writelog(CONFIG["debug_dir"] + "/fail_gwinfo.txt", "{} - Corrupted file.".format(request.environ['REMOTE_ADDR']))
|
writelog(CONFIG["debug_dir"] + "/fail_gwinfo.txt", "{} - Corrupted file.".format(request.environ['REMOTE_ADDR']))
|
||||||
|
|
||||||
|
def gw_name(gw):
|
||||||
|
if gw["gw"] and gw["gwif"]:
|
||||||
|
s = gw["gw"] + " (" + gw["gwif"] + ")"
|
||||||
|
else:
|
||||||
|
s = gw["mac"]
|
||||||
|
return s
|
||||||
|
|
||||||
|
def gw_bat(gw):
|
||||||
|
if gw["batif"] and gw["batmac"]:
|
||||||
|
s = gw["batmac"] + " (" + gw["batif"] + ")"
|
||||||
|
else:
|
||||||
|
s = "---"
|
||||||
|
return s
|
||||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
||||||
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
||||||
|
|
||||||
from ffmap.mysqltools import FreifunkMySQL
|
from ffmap.mysqltools import FreifunkMySQL
|
||||||
|
from ffmap.gwtools import gw_name, gw_bat
|
||||||
from ffmap.misc import *
|
from ffmap.misc import *
|
||||||
from ffmap.config import CONFIG
|
from ffmap.config import CONFIG
|
||||||
|
|
||||||
|
@ -209,6 +210,31 @@ def gws_sum(mysql,selecthood=None):
|
||||||
result[rs["mac"]] = {"routers": rs["count"], "clients": rs["clients"]}
|
result[rs["mac"]] = {"routers": rs["count"], "clients": rs["clients"]}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def gws_info(mysql,selecthood=None):
|
||||||
|
if selecthood:
|
||||||
|
where = "WHERE hood=%s"
|
||||||
|
tup = (selecthood,)
|
||||||
|
else:
|
||||||
|
where = ""
|
||||||
|
tup = ()
|
||||||
|
|
||||||
|
data = mysql.fetchdict("""
|
||||||
|
SELECT router_gw.mac AS mac, gw.name AS gw, stats_page, n1.netif AS gwif, n2.netif AS batif, n2.mac AS batmac
|
||||||
|
FROM router
|
||||||
|
INNER JOIN router_gw ON router.id = router_gw.router
|
||||||
|
LEFT JOIN (
|
||||||
|
gw_netif AS n1
|
||||||
|
INNER JOIN gw ON n1.gw = gw.id
|
||||||
|
LEFT JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
|
||||||
|
) ON router_gw.mac = n1.mac
|
||||||
|
{}
|
||||||
|
GROUP BY router_gw.mac, n2.netif, n2.mac
|
||||||
|
""".format(where),tup,"mac")
|
||||||
|
for d in data.values():
|
||||||
|
d["label"] = gw_name(d)
|
||||||
|
d["batX"] = gw_bat(d)
|
||||||
|
return data
|
||||||
|
|
||||||
def record_global_stats(mysql):
|
def record_global_stats(mysql):
|
||||||
threshold=(utcnow() - datetime.timedelta(days=CONFIG["global_stat_days"])).timestamp()
|
threshold=(utcnow() - datetime.timedelta(days=CONFIG["global_stat_days"])).timestamp()
|
||||||
time = mysql.utctimestamp()
|
time = mysql.utctimestamp()
|
||||||
|
|
|
@ -10,6 +10,7 @@ from ffmap.mysqltools import FreifunkMySQL
|
||||||
from ffmap import stattools
|
from ffmap import stattools
|
||||||
from ffmap.usertools import *
|
from ffmap.usertools import *
|
||||||
from ffmap.routertools import delete_router, ban_router
|
from ffmap.routertools import delete_router, ban_router
|
||||||
|
from ffmap.gwtools import gw_name, gw_bat
|
||||||
from ffmap.web.helpers import *
|
from ffmap.web.helpers import *
|
||||||
from ffmap.config import CONFIG
|
from ffmap.config import CONFIG
|
||||||
from ffmap.misc import writelog, writefulllog
|
from ffmap.misc import writelog, writefulllog
|
||||||
|
@ -119,10 +120,18 @@ def router_info(dbid):
|
||||||
# FIX SQL: only one from router_netif
|
# FIX SQL: only one from router_netif
|
||||||
|
|
||||||
router["gws"] = mysql.fetchall("""
|
router["gws"] = mysql.fetchall("""
|
||||||
SELECT mac, quality, netif, gw_class, selected
|
SELECT router_gw.mac AS mac, quality, router_gw.netif AS netif, gw_class, selected, gw.name AS gw, n1.netif AS gwif, n2.netif AS batif, n2.mac AS batmac
|
||||||
FROM router_gw
|
FROM router_gw
|
||||||
|
LEFT JOIN (
|
||||||
|
gw_netif AS n1
|
||||||
|
INNER JOIN gw ON n1.gw = gw.id
|
||||||
|
LEFT JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
|
||||||
|
) ON router_gw.mac = n1.mac
|
||||||
WHERE router = %s
|
WHERE router = %s
|
||||||
""",(dbid,))
|
""",(dbid,))
|
||||||
|
for gw in router["gws"]:
|
||||||
|
gw["label"] = gw_name(gw)
|
||||||
|
gw["batX"] = gw_bat(gw)
|
||||||
|
|
||||||
router["events"] = mysql.fetchall("""SELECT * FROM router_events WHERE router = %s""",(dbid,))
|
router["events"] = mysql.fetchall("""SELECT * FROM router_events WHERE router = %s""",(dbid,))
|
||||||
router["events"] = mysql.utcawaretuple(router["events"],"time")
|
router["events"] = mysql.utcawaretuple(router["events"],"time")
|
||||||
|
@ -382,6 +391,7 @@ def helper_statistics(mysql,stats,selecthood,selectgw):
|
||||||
hoods_sum = stattools.hoods_sum(mysql,selectgw)
|
hoods_sum = stattools.hoods_sum(mysql,selectgw)
|
||||||
gws = stattools.gws(mysql,selecthood)
|
gws = stattools.gws(mysql,selecthood)
|
||||||
gws_sum = stattools.gws_sum(mysql,selecthood)
|
gws_sum = stattools.gws_sum(mysql,selecthood)
|
||||||
|
gws_info = stattools.gws_info(mysql,selecthood)
|
||||||
mysql.close()
|
mysql.close()
|
||||||
|
|
||||||
return render_template("statistics.html",
|
return render_template("statistics.html",
|
||||||
|
@ -396,7 +406,8 @@ def helper_statistics(mysql,stats,selecthood,selectgw):
|
||||||
hoods_sum = hoods_sum,
|
hoods_sum = hoods_sum,
|
||||||
newest_routers = newest_routers,
|
newest_routers = newest_routers,
|
||||||
gws = gws,
|
gws = gws,
|
||||||
gws_sum = gws_sum
|
gws_sum = gws_sum,
|
||||||
|
gws_info = gws_info
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
writelog(CONFIG["debug_dir"] + "/fail_stats.txt", str(e))
|
writelog(CONFIG["debug_dir"] + "/fail_stats.txt", str(e))
|
||||||
|
|
|
@ -322,7 +322,8 @@
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="neighbours" style="width: 100%; margin-bottom: 6px;">
|
<table class="neighbours" style="width: 100%; margin-bottom: 6px;">
|
||||||
<tr>
|
<tr>
|
||||||
<th>MAC (fastd/l2tp)</th>
|
<th>Gateway</th>
|
||||||
|
<th>batX</th>
|
||||||
<th>Qual</th>
|
<th>Qual</th>
|
||||||
<th>Netif</th>
|
<th>Netif</th>
|
||||||
<th>Class</th>
|
<th>Class</th>
|
||||||
|
@ -333,7 +334,8 @@
|
||||||
{%- else %}
|
{%- else %}
|
||||||
<tr>
|
<tr>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
<td><a href="{{ url_for('router_list', q='selected:^%s$' % gw.mac) }}">{{ gw.mac }}</a></td>
|
<td><a href="{{ url_for('router_list', q='selected:^%s$' % gw.mac) }}">{{ gw.label }}</a></td>
|
||||||
|
<td>{{ gw.batX }}</td>
|
||||||
<td>{{ gw.quality }}</td>
|
<td>{{ gw.quality }}</td>
|
||||||
<td>{{ gw.netif }}</td>
|
<td>{{ gw.netif }}</td>
|
||||||
<td>{{ gw.gw_class }}</td>
|
<td>{{ gw.gw_class }}</td>
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
{%- for mac, value in gws|dictsort %}
|
{%- for mac, value in gws|dictsort %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="firstrow"><a href="{{ url_for('router_list', q='selected:^%s$' % mac) }}">{{ mac }}</a></td>
|
<td class="firstrow"><a href="{{ url_for('router_list', q='selected:^%s$' % mac) }}">{{ gws_info[mac]["label"] }}</a></td>
|
||||||
<td class="success"><span style="font-weight:bold">{{ value["selected"]["online"] or 0 }}</span> / {{ value["others"]["online"] or 0 }}</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="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="warning"><span style="font-weight:bold">{{ value["selected"]["unknown"] or 0 }}</span> / {{ value["others"]["unknown"] or 0 }}</td>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user