show network interfaces
This commit is contained in:
parent
84cf486269
commit
d69bb8a622
|
@ -74,8 +74,8 @@ def load_nodewatcher_xml(mac, xml):
|
|||
"mtu": int(netif.xpath("mtu/text()")[0]),
|
||||
"mac": netif.xpath("mac_addr/text()")[0].lower(),
|
||||
"traffic": {
|
||||
"rx": int(netif.xpath("traffic_rx/text()")[0]),
|
||||
"tx": int(netif.xpath("traffic_tx/text()")[0]),
|
||||
"rx_bytes": int(netif.xpath("traffic_rx/text()")[0]),
|
||||
"tx_bytes": int(netif.xpath("traffic_tx/text()")[0]),
|
||||
},
|
||||
}
|
||||
if len(netif.xpath("ipv6_link_local_addr/text()")) > 0:
|
||||
|
@ -122,6 +122,28 @@ def load_nodewatcher_xml(mac, xml):
|
|||
if router:
|
||||
# keep hood up to date
|
||||
router_update["hood"] = db.hoods.find_one({"position": {"$near": {"$geometry": router["position"]}}})["name"]
|
||||
|
||||
# calculate network io
|
||||
try:
|
||||
if router["system"]["uptime"] < router_update["system"]["uptime"]:
|
||||
timediff = router_update["system"]["uptime"] - router["system"]["uptime"]
|
||||
for netif in router["netifs"]:
|
||||
netif_update = next(filter(lambda n: n["name"] == netif["name"], router_update["netifs"]))
|
||||
rx_diff = netif_update["traffic"]["rx_bytes"] - netif["traffic"]["rx_bytes"]
|
||||
tx_diff = netif_update["traffic"]["tx_bytes"] - netif["traffic"]["tx_bytes"]
|
||||
netif_update["traffic"]["rx"] = rx_diff / timediff
|
||||
netif_update["traffic"]["tx"] = tx_diff / timediff
|
||||
elif router["system"]["uptime"] == router_update["system"]["uptime"]:
|
||||
for netif in router["netifs"]:
|
||||
netif_update = next(filter(lambda n: n["name"] == netif["name"], router_update["netifs"]))
|
||||
netif_update["traffic"]["rx"] = netif["traffic"]["rx"]
|
||||
netif_update["traffic"]["tx"] = netif["traffic"]["tx"]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# calculate RRD statistics (rrdcache?)
|
||||
#FIXME: implementation
|
||||
|
||||
db.routers.update_one({"netifs.mac": mac.lower()}, {"$set": router_update})
|
||||
else:
|
||||
# new router
|
||||
|
@ -172,11 +194,6 @@ def load_nodewatcher_xml(mac, xml):
|
|||
"$slice": -10,
|
||||
}}})
|
||||
|
||||
if status == "online":
|
||||
# calculate RRD statistics (rrdcache?)
|
||||
#FIXME: implementation
|
||||
pass
|
||||
|
||||
def detect_offline_routers():
|
||||
db.routers.update_many({
|
||||
"last_contact": {"$lt": datetime.datetime.utcnow() - datetime.timedelta(minutes=10)},
|
||||
|
|
|
@ -25,3 +25,11 @@ def neighbour_color(quality):
|
|||
@filters.app_template_filter('utc2local')
|
||||
def utc2local(dt):
|
||||
return dt.replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal())
|
||||
|
||||
@filters.app_template_filter('humanize_bytes')
|
||||
def humanize_bytes(num, suffix='B'):
|
||||
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
||||
if abs(num) < 1024.0:
|
||||
return "%3.1f%s%s" % (num, unit, suffix)
|
||||
num /= 1024.0
|
||||
return "%.1f%s%s" % (num, 'Yi', suffix)
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
@ -40,9 +44,5 @@
|
|||
</nav>
|
||||
|
||||
<div class="container main_content">{% block content %}{% endblock %}</div><!-- /.container -->
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
.table-condensed tr:last-child td, th {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
li.list-group-item:hover {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -61,7 +64,7 @@
|
|||
</tr>
|
||||
{%- for neighbour in router.neighbours %}
|
||||
<tr style="background-color: {{ neighbour.quality|neighbour_color }};">
|
||||
<td><a href="{{ url_for('router_info', dbid=neighbour._id) }}">{{ neighbour.hostname }}</td>
|
||||
<td><a href="{{ url_for('router_info', dbid=neighbour._id) }}">{{ neighbour.hostname }}</a></td>
|
||||
<td>{{ neighbour.mac }}</td>
|
||||
<td>{{ neighbour.quality }}</td>
|
||||
<td>{{ neighbour.net_if }}</td>
|
||||
|
@ -85,6 +88,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">System</div>
|
||||
|
@ -124,4 +129,59 @@
|
|||
</div>
|
||||
{%- endif %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Network Interfaces</div>
|
||||
<div class="panel-body">
|
||||
</div>
|
||||
<ul class="list-group" id="netif-list">
|
||||
{# make sure that br-mesh is on top of the list #}
|
||||
{%- for netif in router.netifs if netif.name == 'br-mesh' %}
|
||||
<li class="list-group-item active" data-mac="{{ netif.mac }}">
|
||||
<h4 class="list-group-item-heading"><div class="row">
|
||||
<div class="col-md-6">{{ netif.name }}</div>
|
||||
<div class="col-md-6 text-right">{{ netif.mac|upper }}</div>
|
||||
</div></h4>
|
||||
<p class="list-group-item-text"><div class="row">
|
||||
<div class="col-md-6">{{ netif.ipv6_fe80_addr }}</div>
|
||||
{%- if netif.traffic.rx is defined %}
|
||||
<div class="col-md-6 text-right">
|
||||
<span class="glyphicon glyphicon-arrow-down"></span>{{ netif.traffic.rx|humanize_bytes }}/s
|
||||
<span class="glyphicon glyphicon-arrow-up"></span>{{ netif.traffic.tx|humanize_bytes }}/s
|
||||
</div>
|
||||
{%- endif %}
|
||||
</div></p>
|
||||
</li>
|
||||
{%- endfor %}
|
||||
{%- for netif in router.netifs if netif.name != 'br-mesh' %}
|
||||
<li class="list-group-item" data-mac="{{ netif.mac }}">
|
||||
<h4 class="list-group-item-heading"><div class="row">
|
||||
<div class="col-md-6">{{ netif.name }}</div>
|
||||
<div class="col-md-6 text-right">{{ netif.mac|upper }}</div>
|
||||
</div></h4>
|
||||
<p class="list-group-item-text"><div class="row">
|
||||
<div class="col-md-6">{{ netif.ipv6_fe80_addr }}</div>
|
||||
{%- if netif.traffic.rx is defined %}
|
||||
<div class="col-md-6 text-right">
|
||||
<span class="glyphicon glyphicon-arrow-down"></span>{{ netif.traffic.rx|humanize_bytes }}/s
|
||||
<span class="glyphicon glyphicon-arrow-up"></span>{{ netif.traffic.tx|humanize_bytes }}/s
|
||||
</div>
|
||||
{%- endif %}
|
||||
</div></p>
|
||||
</li>
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#netif-list li").on("click", function() {
|
||||
$("#netif-list li").removeClass("active");
|
||||
$(this).addClass("active");
|
||||
this.getAttribute("data-mac")
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue