Add Interfaces usage

main
pporcheret 2023-07-03 13:34:09 +02:00
parent c89e9446ec
commit 9ddea4e264
2 changed files with 15 additions and 9 deletions

View File

@ -95,8 +95,11 @@ class Network:
num=0 num=0
for interface in psutil.net_if_addrs(): for interface in psutil.net_if_addrs():
exec("self.net_"+str(num)+" = {}") exec("self.net_"+str(num)+" = {}")
interface_usage = psutil.net_io_counters(pernic=True)
for detail in psutil.net_if_addrs()[interface]: for detail in psutil.net_if_addrs()[interface]:
exec("self.net_"+str(num)+"['name'] = '"+str(interface)+"'") exec("self.net_"+str(num)+"['name'] = '"+str(interface)+"'")
exec("self.net_"+str(num)+"['bytes_sent'] = '"+str(human_size(interface_usage[interface].bytes_sent))+"'")
exec("self.net_"+str(num)+"['bytes_recv'] = '"+str(human_size(interface_usage[interface].bytes_recv))+"'")
ip_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") ip_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
if ip_pattern.match(detail.address): if ip_pattern.match(detail.address):
exec("self.net_"+str(num)+"['address_v4'] = '"+str(detail.address)+"'") exec("self.net_"+str(num)+"['address_v4'] = '"+str(detail.address)+"'")

View File

@ -133,10 +133,10 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
</div> </div>
<div class="card-body"> <div class="card-body">
<table class="table"> <table class="table">
<tr><td>Name</td><td>IPv4</td><td>Netmask v4</td><td>IPv6</td><td>Netmask v6</td></tr> <tr><td>Name</td><td>IPv4</td><td>Netmask v4</td><td>IPv6</td><td>Netmask v6</td><td>Sent</td><td>Received</td></tr>
{% for key in full %} {% for key in full %}
{% if key.startswith('net_') %} {% if key.startswith('net_') %}
<tr><td>{{ full[key]['name'] }}</td><td>{{ full[key]['address_v4'] }}</td><td>{{ full[key]['netmask_v4'] }}</td><td>{{ full[key]['address_v6'] }}</td><td>{{ full[key]['netmask_v6'] }}</td><tr> <tr><td>{{ full[key]['name'] }}</td><td>{{ full[key]['address_v4'] }}</td><td>{{ full[key]['netmask_v4'] }}</td><td>{{ full[key]['address_v6'] }}</td><td>{{ full[key]['netmask_v6'] }}</td><td>{{ full[key]['bytes_sent'] }}</td><td>{{ full[key]['bytes_recv'] }}</td><tr>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</table> </table>
@ -148,25 +148,28 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
const config = { const config = {
type: 'line', type: 'line',
data: { data: {
labels: Array(30).fill("0000-00-00 00:00:00"), labels: Array(60).fill("0000-00-00 00:00:00"),
datasets: [{ datasets: [{
label: "CPU %", label: "CPU %",
backgroundColor: 'rgb(0, 191, 255)', backgroundColor: 'rgb(0, 191, 255)',
borderColor: 'rgb(0, 191, 255)', borderColor: 'rgb(0, 191, 255)',
data: Array(30).fill(null), data: Array(60).fill(null),
fill: false, fill: false,
pointRadius: 0,
},{ },{
label: "Mem %", label: "Mem %",
backgroundColor: 'rgb(255,240,100)', backgroundColor: 'rgb(255,200,20)',
borderColor: 'rgb(255, 240, 100)', borderColor: 'rgb(255,200,20)',
data: Array(30).fill(null), data: Array(60).fill(null),
fill: false, fill: false,
pointRadius: 0,
},{ },{
label: "Swap %", label: "Swap %",
backgroundColor: 'rgb(255, 20, 100)', backgroundColor: 'rgb(255, 20, 100)',
borderColor: 'rgb(255, 20, 100)', borderColor: 'rgb(255, 20, 100)',
data: Array(30).fill(null), data: Array(60).fill(null),
fill: false, fill: false,
pointRadius: 0,
}], }],
}, },
options: { options: {
@ -212,7 +215,7 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
const source = new EventSource("/chart-ressources/{{ node }}"); const source = new EventSource("/chart-ressources/{{ node }}");
source.onmessage = function (event) { source.onmessage = function (event) {
const data = JSON.parse(event.data); const data = JSON.parse(event.data);
if (config.data.labels.length === 30) { if (config.data.labels.length === 60) {
config.data.labels.shift(); config.data.labels.shift();
config.data.datasets[0].data.shift(); config.data.datasets[0].data.shift();
config.data.datasets[1].data.shift(); config.data.datasets[1].data.shift();