router.html: Show former neighbors in neighbor stats plot
If a router is currently not connected as neighbor, we don't see its history. This patch shows all current and former neighbors. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
7955e60f2f
commit
54764f7f43
|
@ -48,10 +48,15 @@ def load_neighbor_stats(dbid):
|
||||||
""",(dbid,))
|
""",(dbid,))
|
||||||
mysql.close()
|
mysql.close()
|
||||||
|
|
||||||
|
neighdata = {}
|
||||||
|
|
||||||
for ns in neighfetch:
|
for ns in neighfetch:
|
||||||
ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)}
|
ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)}
|
||||||
|
if not ns["mac"] in neighdata:
|
||||||
|
neighdata[ns["mac"]] = []
|
||||||
|
neighdata[ns["mac"]].append(ns)
|
||||||
|
|
||||||
r = make_response(json.dumps(neighfetch))
|
r = make_response(json.dumps(neighdata))
|
||||||
r.mimetype = 'application/json'
|
r.mimetype = 'application/json'
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
|
@ -223,22 +223,26 @@ def router_info(dbid):
|
||||||
desc = "Ethernet Multi-Port"
|
desc = "Ethernet Multi-Port"
|
||||||
n["description"] = desc
|
n["description"] = desc
|
||||||
n["color"] = color
|
n["color"] = color
|
||||||
|
|
||||||
## Set color for neighbors AFTER json if clause
|
## Set color for neighbors AFTER json if clause
|
||||||
for n in router["neighbours"]:
|
for n in router["neighbours"]:
|
||||||
n["color"] = neighbor_color(n["quality"],router["routing_protocol"])
|
n["color"] = neighbor_color(n["quality"],router["routing_protocol"])
|
||||||
|
|
||||||
router["stats"] = mysql.fetchall("""SELECT * FROM router_stats WHERE router = %s""",(dbid,))
|
router["stats"] = mysql.fetchall("""SELECT * FROM router_stats WHERE router = %s""",(dbid,))
|
||||||
for s in router["stats"]:
|
for s in router["stats"]:
|
||||||
s["time"] = mysql.utcawareint(s["time"])
|
s["time"] = mysql.utcawareint(s["time"])
|
||||||
|
|
||||||
threshold_neighstats = (utcnow() - datetime.timedelta(hours=24)).timestamp()
|
threshold_neighstats = (utcnow() - datetime.timedelta(hours=24)).timestamp()
|
||||||
neighfetch = mysql.fetchall("""
|
neighfetch = mysql.fetchall("""
|
||||||
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s AND time > %s
|
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s AND time > %s
|
||||||
""",(dbid,threshold_neighstats,))
|
""",(dbid,threshold_neighstats,))
|
||||||
|
|
||||||
|
neighdata = {}
|
||||||
for ns in neighfetch:
|
for ns in neighfetch:
|
||||||
ns["time"] = mysql.utcawareint(ns["time"])
|
ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)}
|
||||||
|
if not ns["mac"] in neighdata:
|
||||||
|
neighdata[ns["mac"]] = []
|
||||||
|
neighdata[ns["mac"]].append(ns)
|
||||||
|
|
||||||
gwfetch = mysql.fetchall("""
|
gwfetch = mysql.fetchall("""
|
||||||
SELECT quality, mac, time FROM router_stats_gw WHERE router = %s
|
SELECT quality, mac, time FROM router_stats_gw WHERE router = %s
|
||||||
|
@ -319,7 +323,7 @@ def router_info(dbid):
|
||||||
router = router,
|
router = router,
|
||||||
mac = mac,
|
mac = mac,
|
||||||
tileurls = tileurls,
|
tileurls = tileurls,
|
||||||
neighstats = neighfetch,
|
neighstats = neighdata,
|
||||||
gwstats = gwfetch,
|
gwstats = gwfetch,
|
||||||
authuser = is_authorized(router["user"], session),
|
authuser = is_authorized(router["user"], session),
|
||||||
authadmin = session.get('admin')
|
authadmin = session.get('admin')
|
||||||
|
|
|
@ -102,25 +102,28 @@ function network_graph(netif) {
|
||||||
function neighbour_graph(neighbours) {
|
function neighbour_graph(neighbours) {
|
||||||
var meshstat = $("#meshstat");
|
var meshstat = $("#meshstat");
|
||||||
var pdata = [];
|
var pdata = [];
|
||||||
for (j=0; j<neighbours.length; j++) {
|
var len, i;
|
||||||
var label = neighbours[j].name;
|
var mac;
|
||||||
|
|
||||||
// add network interface when there are multiple links to same node
|
for (var j in neigh_stats) {
|
||||||
var k;
|
var dataset = neigh_stats[j];
|
||||||
for(k=0; k<neighbours.length; k++) {
|
var label = j;
|
||||||
if(label == neighbours[k].name && k != j) {
|
var data = [];
|
||||||
label += "@" + neighbours[j].netif;
|
for(n=0; n<neighbours.length; n++) {
|
||||||
|
if (neighbours[n].mac != j) { continue; }
|
||||||
|
label = neighbours[n].name;
|
||||||
|
// add network interface when there are multiple links to same node
|
||||||
|
var k;
|
||||||
|
for(k=0; k<neighbours.length; k++) {
|
||||||
|
if(label == neighbours[k].name && k != n) {
|
||||||
|
label += "@" + neighbours[n].netif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (len=dataset.length, i=0; i<len; i++) {
|
||||||
var mac = neighbours[j].mac;
|
|
||||||
var data = [];
|
|
||||||
var len, i;
|
|
||||||
for (len=neigh_stats.length, i=0; i<len; i++) {
|
|
||||||
if (neigh_stats[i].mac != mac) { continue; }
|
|
||||||
try {
|
try {
|
||||||
var quality = neigh_stats[i].quality;
|
var quality = dataset[i].quality;
|
||||||
var date_value = neigh_stats[i].time.$date;
|
var date_value = dataset[i].time.$date;
|
||||||
if(quality == null) {
|
if(quality == null) {
|
||||||
quality = 0;
|
quality = 0;
|
||||||
}
|
}
|
||||||
|
@ -132,6 +135,7 @@ function neighbour_graph(neighbours) {
|
||||||
}
|
}
|
||||||
pdata.push({"label": label, "data": data});
|
pdata.push({"label": label, "data": data});
|
||||||
}
|
}
|
||||||
|
if(pdata.length == 0) { pdata.push({"label": "empty", "data": []}); }
|
||||||
var plot = $.plot(meshstat, pdata, {
|
var plot = $.plot(meshstat, pdata, {
|
||||||
xaxis: {mode: "time", timezone: "browser"},
|
xaxis: {mode: "time", timezone: "browser"},
|
||||||
selection: {mode: "x"},
|
selection: {mode: "x"},
|
||||||
|
|
|
@ -419,7 +419,7 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var router_stats = {{ router.stats|statbson2json|safe }};
|
var router_stats = {{ router.stats|statbson2json|safe }};
|
||||||
var netif_stats = null;
|
var netif_stats = null;
|
||||||
var neigh_stats = {{ neighstats|statbson2json|safe }};
|
var neigh_stats = {{ neighstats|safe }};
|
||||||
var gw_stats = {{ gwstats|statbson2json|safe }};
|
var gw_stats = {{ gwstats|statbson2json|safe }};
|
||||||
var neighbours = [
|
var neighbours = [
|
||||||
{%- for neighbour in router.neighbours %}
|
{%- for neighbour in router.neighbours %}
|
||||||
|
|
Loading…
Reference in New Issue