diff --git a/ffmap/web/api.py b/ffmap/web/api.py index 55a0fc1..7d5782e 100755 --- a/ffmap/web/api.py +++ b/ffmap/web/api.py @@ -28,11 +28,16 @@ def load_netif_stats(dbid): influ = FreifunkInflux() netiffetch = influ.fetchlist('SELECT netif, rx, tx, time FROM router_netif.stat WHERE router = $router AND netif = $netif ORDER BY time ASC',{"router": dbid, "netif": netif}) + netifstats = [] for ns in netiffetch: - ns["time"] = {"$date": int(influ.utcawareint(ns["time"]).timestamp()*1000)} + netifstats.append({ + "t": {"$date": int(influ.utcawareint(ns["time"]).timestamp()*1000)}, + "rx": ns["rx"], + "tx": ns["tx"] + }) - r = make_response(json.dumps(netiffetch)) + r = make_response(json.dumps(netifstats)) r.mimetype = 'application/json' return r #return make_response(json.dumps({})) @@ -47,10 +52,12 @@ def load_neighbor_stats(dbid): neighdata = {} for ns in neighfetch: - ns["time"] = {"$date": int(influ.utcawareint(ns["time"]).timestamp()*1000)} if not ns["mac"] in neighdata: neighdata[ns["mac"]] = [] - neighdata[ns["mac"]].append(ns) + neighdata[ns["mac"]].append({ + "t": {"$date": int(influ.utcawareint(ns["time"]).timestamp()*1000)}, + "q": ns["quality"] + }) r = make_response(json.dumps(neighdata)) r.mimetype = 'application/json' diff --git a/ffmap/web/application.py b/ffmap/web/application.py index 142b764..59d43a8 100755 --- a/ffmap/web/application.py +++ b/ffmap/web/application.py @@ -270,8 +270,24 @@ def router_info(dbid): for n in router["neighbours"]: n["color"] = neighbor_color(n["quality"],n["netif"],router["routing_protocol"]) - router["stats"] = influ.fetchlist('SELECT * FROM router_default.stat WHERE router = $router ORDER BY time ASC',{"router": dbid}) - for s in router["stats"]: + router_stats = influ.fetchlist('SELECT * FROM router_default.stat WHERE router = $router ORDER BY time ASC',{"router": dbid}) + router["stats"] = [] + for s in router_stats: + router["stats"].append({ + "t": mysql.utcawareint(s["time"]), + "a2": s["airtime_w2"], + "a5": s["airtime_w5"], + "c": s["clients"], + "ce": s["clients_eth"], + "c2": s["clients_w2"], + "c5": s["clients_w5"], + "l": s["loadavg"], + "mb": s["sys_membuff"], + "mc": s["sys_memcache"], + "mf": s["sys_memfree"], + "pr": s["sys_procrun"], + "pt": s["sys_proctot"] + }) s["time"] = mysql.utcawareint(s["time"]) neighfetch = influ.fetchlist('SELECT quality, mac, time FROM router_neighbor.stat WHERE router = $router AND time > now() - 24h ORDER BY time ASC',{"router": dbid}) @@ -279,11 +295,13 @@ def router_info(dbid): neighdata = {} neighmacint = [] for ns in neighfetch: - ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)} if not ns["mac"] in neighdata: neighdata[ns["mac"]] = [] neighmacint.append(mac2int(ns["mac"])) - neighdata[ns["mac"]].append(ns) + neighdata[ns["mac"]].append({ + "t": {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)}, + "q": ns["quality"] + }) #neighident = mysql.fetchall(""" # SELECT snb.mac, r.hostname, n.netif @@ -317,8 +335,13 @@ def router_info(dbid): neighlabel[int2shortmac(ni["mac"])] = label + append gwfetch = influ.fetchlist('SELECT quality, mac, time FROM router_gw.stat WHERE router = $router ORDER BY time ASC',{"router": dbid}) + gwstats = [] for ns in gwfetch: - ns["time"] = mysql.utcawareint(ns["time"]) + gwstats.append({ + "t": mysql.utcawareint(ns["time"]), + "q": ns["quality"], + "m": ns["mac"] + }) if request.method == 'POST': if request.form.get("act") == "delete": @@ -394,7 +417,7 @@ def router_info(dbid): tileurls = tileurls, neighstats = neighdata, neighlabel = neighlabel, - gwstats = gwfetch, + gwstats = gwstats, authuser = is_authorized(router["user"], session), authadmin = session.get('admin') ) diff --git a/ffmap/web/filters.py b/ffmap/web/filters.py index 8e3af2f..d0b146a 100644 --- a/ffmap/web/filters.py +++ b/ffmap/web/filters.py @@ -152,6 +152,12 @@ def statbson_to_json(bsn): point["time"] = {"$date": int(point["time"].timestamp()*1000)} return json.dumps(bsn) +@filters.app_template_filter('shortbson2json') +def shortbson_to_json(bsn): + for point in bsn: + point["t"] = {"$date": int(point["t"].timestamp()*1000)} + return json.dumps(bsn) + @filters.app_template_filter('nbsp') def nbsp(txt): return txt.replace(" ", " ") diff --git a/ffmap/web/static/js/graph.js b/ffmap/web/static/js/graph.js index e7b0b2f..4ef2c3d 100644 --- a/ffmap/web/static/js/graph.js +++ b/ffmap/web/static/js/graph.js @@ -74,7 +74,7 @@ function network_graph(netif_stats, field, tx_label, rx_label) { try { var tx_value = netif_stats[i].tx; var rx_value = netif_stats[i].rx; - var date_value = netif_stats[i].time.$date; + var date_value = netif_stats[i].t.$date; if(tx_value != null && rx_value != null) { tx.push([date_value, tx_value * 8]); rx.push([date_value, rx_value * 8]); @@ -114,8 +114,8 @@ function neighbour_graph(neigh_label) { } for (len=dataset.length, i=0; i