From 96e92f5805f37d960c3f7a1ab42f481f075b5013 Mon Sep 17 00:00:00 2001 From: pporcheret Date: Wed, 5 Jul 2023 11:26:54 +0200 Subject: [PATCH] Dynamically update values --- README.md | 3 ++- agent.py | 1 + app.py | 31 ++++++++++++++++++++++++++++--- templates/index.html | 29 +++++++++++++++++------------ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 30a9fd5..5b18bef 100644 --- a/README.md +++ b/README.md @@ -193,11 +193,12 @@ v2: - [x] Create Live view of SWAP,CPU,Memory usage - [x] Adding Chart to interface -v2.1 On going : +v2.1: - [x] Add Network usage - [x] Add boot time - [x] Update dynamically Progress Bar +- [x] Update dynamically Ressources details Next: diff --git a/agent.py b/agent.py index e251e2d..11ec17f 100755 --- a/agent.py +++ b/agent.py @@ -31,6 +31,7 @@ class ENV: self.cpu_number = psutil.cpu_count(logical=False) self.vcpu = psutil.cpu_count() self.mem_max = human_size(psutil.virtual_memory().total) + self.boot_time = psutil.boot_time() class CPU: def __init__(self): diff --git a/app.py b/app.py index 817e841..5a7e228 100755 --- a/app.py +++ b/app.py @@ -51,9 +51,34 @@ def get_ressources(nodename): json_data = json.dumps( { "time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - "cpu": full['cpu']['percent'], - "mem": full['mem']['percent'], - "swap": full['swap']['percent'], + "cpu_percent": full['cpu']['percent'], + "mem_percent": full['mem']['percent'], + "swap_percent": full['swap']['percent'], + "cpu_time_user": full['cpu']['time_user'], + "cpu_time_nice": full['cpu']['time_nice'], + "cpu_time_system": full['cpu']['time_system'], + "cpu_time_idle": full['cpu']['time_idle'], + "cpu_time_iowait": full['cpu']['time_iowait'], + "cpu_time_irq": full['cpu']['time_irq'], + "cpu_time_softirq": full['cpu']['time_softirq'], + "cpu_time_steal": full['cpu']['time_steal'], + "cpu_time_guest": full['cpu']['time_guest'], + "cpu_time_guest_nice": full['cpu']['time_nice'], + "mem_total": full['mem']['total'], + "mem_available": full['mem']['available'], + "mem_used": full['mem']['used'], + "mem_free": full['mem']['free'], + "mem_active": full['mem']['active'], + "mem_inactive": full['mem']['inactive'], + "mem_buffers": full['mem']['buffers'], + "mem_cached": full['mem']['cached'], + "mem_shared": full['mem']['shared'], + "mem_slab": full['mem']['slab'], + "swap_total": full['swap']['total'], + "swap_used": full['swap']['used'], + "swap_free": full['swap']['free'], + "swap_sin": full['swap']['sin'], + "swap_sout": full['swap']['sout'], } ) yield f"data:{json_data}\n\n" diff --git a/templates/index.html b/templates/index.html index 435f45e..05bcabe 100644 --- a/templates/index.html +++ b/templates/index.html @@ -83,7 +83,7 @@ CPU
{{ full['cpu']['percent'] }}%
- + user : {{ full['cpu']['time_user'] }} / nice : {{ full['cpu']['time_nice'] }} / system : {{ full['cpu']['time_system'] }} / idle : {{ full['cpu']['time_idle'] }} / iowait : {{ full['cpu']['time_iowait'] }} / irq : {{ full['cpu']['time_irq'] }} / softirq : {{ full['cpu']['time_softirq'] }} / steal : {{ full['cpu']['time_steal'] }} / guest : {{ full['cpu']['time_guest'] }} / guest nice : {{ full['cpu']['time_guest_nice'] }}
@@ -91,7 +91,7 @@ MEM
{{ full['mem']['percent'] }}%
- + total : {{ full['mem']['total'] }} / available : {{ full['mem']['available'] }} / used : {{ full['mem']['used'] }} / free : {{ full['mem']['free'] }} / active : {{ full['mem']['active'] }} / inactive : {{ full['mem']['inactive'] }} / buffers : {{ full['mem']['buffers'] }} / cached : {{ full['mem']['cached'] }} / shared : {{ full['mem']['shared'] }} / slab : {{ full['mem']['slab'] }}
@@ -99,7 +99,7 @@ SWAP
{{ full['swap']['percent'] }}%
- + total : {{ full['swap']['total'] }} / used : {{ full['swap']['used'] }} / free : {{ full['swap']['free'] }} / sin : {{ full['swap']['sin'] }} / sout : {{ full['swap']['sout'] }} @@ -222,20 +222,25 @@ total : {{ full[key]['size_total'] }} / used : {{ full[key]['size_used'] }} / fr config.data.datasets[2].data.shift(); } config.data.labels.push(data.time); - config.data.datasets[0].data.push(data.cpu); - config.data.datasets[1].data.push(data.mem); - config.data.datasets[2].data.push(data.swap); + config.data.datasets[0].data.push(data.cpu_percent); + config.data.datasets[1].data.push(data.mem_percent); + config.data.datasets[2].data.push(data.swap_percent); lineChart.update(); - $("#cpubar").html(data.cpu+"%"); - $("#membar").html(data.mem+"%"); - $("#swapbar").html(data.swap+"%"); + $("#cpubar").html(data.cpu_percent+"%"); + $("#membar").html(data.mem_percent+"%"); + $("#swapbar").html(data.swap_percent+"%"); + $("#cpudetail").html("user : "+data.cpu_time_user+" / nice : "+data.cpu_time_nice+" / system : "+data.cpu_time_system+" / idle : "+data.cpu_time_idle+" / iowait : "+data.cpu_time_iowait+" / irq : "+data.cpu_time_irq+" / softirq : "+data.cpu_time_softirq+" / steal : "+data.cpu_time_steal+" / guest : "+data.cpu_time_guest+" / guest nice : "+data.cpu_time_guest_nice); + $("#swapdetail").html("total : "+data.swap_total+" / used : "+data.swap_used+" / free : "+data.swap_free+" / sin : "+data.swap_sin+" / sout : "+data.swap_sout); + $("#memdetail").html("total : "+data.mem_total+" / available : "+data.mem_available+" / used : "+data.mem_used+" / free : "+data.mem_free+" / active : "+data.mem_active+" / inactive : "+data.mem_inactive+" / buffers : "+data.mem_buffers+" / cached : "+data.mem_cached+" / shared : "+data.mem_shared+" / slab : "+data.mem_slab); var element_cpubar = document.getElementById("cpubar"); var element_membar = document.getElementById("membar"); var element_swapbar = document.getElementById("swapbar"); - element_cpubar.style.width = data.cpu+"%" - element_membar.style.width = data.mem+"%" - element_swapbar.style.width = data.swap+"%" + var element_cpudetail = document.getElementById("cpudetail"); + + element_cpubar.style.width = data.cpu_percent+"%" + element_membar.style.width = data.mem_percent+"%" + element_swapbar.style.width = data.swap_percent+"%" } });