Add Interfaces usage
This commit is contained in:
		
							parent
							
								
									c89e9446ec
								
							
						
					
					
						commit
						9ddea4e264
					
				
							
								
								
									
										3
									
								
								agent.py
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								agent.py
									
									
									
									
									
								
							@ -95,8 +95,11 @@ class Network:
 | 
			
		||||
        num=0
 | 
			
		||||
        for interface in psutil.net_if_addrs():
 | 
			
		||||
            exec("self.net_"+str(num)+" = {}")
 | 
			
		||||
            interface_usage = psutil.net_io_counters(pernic=True)
 | 
			
		||||
            for detail in psutil.net_if_addrs()[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}$")
 | 
			
		||||
                if ip_pattern.match(detail.address):
 | 
			
		||||
                    exec("self.net_"+str(num)+"['address_v4'] = '"+str(detail.address)+"'")
 | 
			
		||||
 | 
			
		||||
@ -133,10 +133,10 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="card-body">
 | 
			
		||||
<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 %}
 | 
			
		||||
{% 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 %}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
</table>
 | 
			
		||||
@ -148,25 +148,28 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
 | 
			
		||||
        const config = {
 | 
			
		||||
            type: 'line',
 | 
			
		||||
            data: {
 | 
			
		||||
                labels: Array(30).fill("0000-00-00 00:00:00"),
 | 
			
		||||
                labels: Array(60).fill("0000-00-00 00:00:00"),
 | 
			
		||||
                datasets: [{
 | 
			
		||||
                    label: "CPU %",
 | 
			
		||||
                    backgroundColor: 'rgb(0, 191, 255)',
 | 
			
		||||
                    borderColor: 'rgb(0, 191, 255)',
 | 
			
		||||
                    data: Array(30).fill(null),
 | 
			
		||||
                    data: Array(60).fill(null),
 | 
			
		||||
                    fill: false,
 | 
			
		||||
                    pointRadius: 0,
 | 
			
		||||
                },{
 | 
			
		||||
                    label: "Mem %",
 | 
			
		||||
                    backgroundColor: 'rgb(255,240,100)',
 | 
			
		||||
                    borderColor: 'rgb(255, 240, 100)',
 | 
			
		||||
                    data: Array(30).fill(null),
 | 
			
		||||
                    backgroundColor: 'rgb(255,200,20)',
 | 
			
		||||
                    borderColor: 'rgb(255,200,20)',
 | 
			
		||||
                    data: Array(60).fill(null),
 | 
			
		||||
                    fill: false,
 | 
			
		||||
                    pointRadius: 0,
 | 
			
		||||
                },{
 | 
			
		||||
                    label: "Swap %",
 | 
			
		||||
                    backgroundColor: 'rgb(255, 20, 100)',
 | 
			
		||||
                    borderColor: 'rgb(255, 20, 100)',
 | 
			
		||||
                    data: Array(30).fill(null),
 | 
			
		||||
                    data: Array(60).fill(null),
 | 
			
		||||
                    fill: false,
 | 
			
		||||
                    pointRadius: 0,
 | 
			
		||||
                }],
 | 
			
		||||
            },
 | 
			
		||||
            options: {
 | 
			
		||||
@ -212,7 +215,7 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr
 | 
			
		||||
        const source = new EventSource("/chart-ressources/{{ node }}");
 | 
			
		||||
        source.onmessage = function (event) {
 | 
			
		||||
            const data = JSON.parse(event.data);
 | 
			
		||||
            if (config.data.labels.length === 30) {
 | 
			
		||||
            if (config.data.labels.length === 60) {
 | 
			
		||||
                config.data.labels.shift();
 | 
			
		||||
                config.data.datasets[0].data.shift();
 | 
			
		||||
                config.data.datasets[1].data.shift();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user