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,))
|
||||
mysql.close()
|
||||
|
||||
neighdata = {}
|
||||
|
||||
for ns in neighfetch:
|
||||
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'
|
||||
return r
|
||||
|
||||
|
|
|
@ -223,22 +223,26 @@ def router_info(dbid):
|
|||
desc = "Ethernet Multi-Port"
|
||||
n["description"] = desc
|
||||
n["color"] = color
|
||||
|
||||
|
||||
## Set color for neighbors AFTER json if clause
|
||||
for n in router["neighbours"]:
|
||||
n["color"] = neighbor_color(n["quality"],router["routing_protocol"])
|
||||
|
||||
|
||||
router["stats"] = mysql.fetchall("""SELECT * FROM router_stats WHERE router = %s""",(dbid,))
|
||||
for s in router["stats"]:
|
||||
s["time"] = mysql.utcawareint(s["time"])
|
||||
|
||||
|
||||
threshold_neighstats = (utcnow() - datetime.timedelta(hours=24)).timestamp()
|
||||
neighfetch = mysql.fetchall("""
|
||||
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s AND time > %s
|
||||
""",(dbid,threshold_neighstats,))
|
||||
|
||||
|
||||
neighdata = {}
|
||||
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("""
|
||||
SELECT quality, mac, time FROM router_stats_gw WHERE router = %s
|
||||
|
@ -319,7 +323,7 @@ def router_info(dbid):
|
|||
router = router,
|
||||
mac = mac,
|
||||
tileurls = tileurls,
|
||||
neighstats = neighfetch,
|
||||
neighstats = neighdata,
|
||||
gwstats = gwfetch,
|
||||
authuser = is_authorized(router["user"], session),
|
||||
authadmin = session.get('admin')
|
||||
|
|
|
@ -102,25 +102,28 @@ function network_graph(netif) {
|
|||
function neighbour_graph(neighbours) {
|
||||
var meshstat = $("#meshstat");
|
||||
var pdata = [];
|
||||
for (j=0; j<neighbours.length; j++) {
|
||||
var label = neighbours[j].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 != j) {
|
||||
label += "@" + neighbours[j].netif;
|
||||
var len, i;
|
||||
var mac;
|
||||
|
||||
for (var j in neigh_stats) {
|
||||
var dataset = neigh_stats[j];
|
||||
var label = j;
|
||||
var data = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
for (len=dataset.length, i=0; i<len; i++) {
|
||||
try {
|
||||
var quality = neigh_stats[i].quality;
|
||||
var date_value = neigh_stats[i].time.$date;
|
||||
var quality = dataset[i].quality;
|
||||
var date_value = dataset[i].time.$date;
|
||||
if(quality == null) {
|
||||
quality = 0;
|
||||
}
|
||||
|
@ -132,6 +135,7 @@ function neighbour_graph(neighbours) {
|
|||
}
|
||||
pdata.push({"label": label, "data": data});
|
||||
}
|
||||
if(pdata.length == 0) { pdata.push({"label": "empty", "data": []}); }
|
||||
var plot = $.plot(meshstat, pdata, {
|
||||
xaxis: {mode: "time", timezone: "browser"},
|
||||
selection: {mode: "x"},
|
||||
|
|
|
@ -419,7 +419,7 @@
|
|||
<script type="text/javascript">
|
||||
var router_stats = {{ router.stats|statbson2json|safe }};
|
||||
var netif_stats = null;
|
||||
var neigh_stats = {{ neighstats|statbson2json|safe }};
|
||||
var neigh_stats = {{ neighstats|safe }};
|
||||
var gw_stats = {{ gwstats|statbson2json|safe }};
|
||||
var neighbours = [
|
||||
{%- for neighbour in router.neighbours %}
|
||||
|
|
Loading…
Reference in New Issue