Make Sysinfo running on other linux
This commit is contained in:
parent
e1a3653b33
commit
cf8c1a9d58
2 changed files with 50 additions and 35 deletions
|
@ -452,36 +452,38 @@ function getDapnetMessages(document, event) {
|
||||||
|
|
||||||
function getSysInfo(document, event) {
|
function getSysInfo(document, event) {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
logIt(event.data);
|
if (event.data.startsWith("SYSINFO")) {
|
||||||
data = event.data;
|
logIt(event.data);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
data = event.data;
|
||||||
document.getElementById("cputemp").innerHTML = parseFloat(data.substring(data.indexOf("cputemp:") + 8, data.indexOf(" "))).toFixed(1);
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cputemp").innerHTML = parseFloat(data.substring(data.indexOf("cputemp:") + 8, data.indexOf(" "))).toFixed(1);
|
||||||
document.getElementById("cpufrg").innerHTML = data.substring(data.indexOf("cpufrg:") + 7, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cpufrg").innerHTML = data.substring(data.indexOf("cpufrg:") + 7, data.indexOf(" "));
|
||||||
document.getElementById("cpuusage").innerHTML = data.substring(data.indexOf("cpuusage:") + 9, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cpuusage").innerHTML = data.substring(data.indexOf("cpuusage:") + 9, data.indexOf(" "));
|
||||||
document.getElementById("cpu_load1").innerHTML = data.substring(data.indexOf("cpu_load1:") + 10, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cpu_load1").innerHTML = data.substring(data.indexOf("cpu_load1:") + 10, data.indexOf(" "));
|
||||||
document.getElementById("cpu_load5").innerHTML = data.substring(data.indexOf("cpu_load5:") + 10, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cpu_load5").innerHTML = data.substring(data.indexOf("cpu_load5:") + 10, data.indexOf(" "));
|
||||||
document.getElementById("cpu_load15").innerHTML = data.substring(data.indexOf("cpu_load15:") + 11, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("cpu_load15").innerHTML = data.substring(data.indexOf("cpu_load15:") + 11, data.indexOf(" "));
|
||||||
document.getElementById("ram_total").innerHTML = Math.round(data.substring(data.indexOf("ram_total:") + 10, data.indexOf(" ")));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("ram_total").innerHTML = Math.round(data.substring(data.indexOf("ram_total:") + 10, data.indexOf(" ")));
|
||||||
document.getElementById("ram_used").innerHTML = Math.round(data.substring(data.indexOf("ram_used:") + 9, data.indexOf(" ")));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("ram_used").innerHTML = Math.round(data.substring(data.indexOf("ram_used:") + 9, data.indexOf(" ")));
|
||||||
document.getElementById("ram_free").innerHTML = Math.round(data.substring(data.indexOf("ram_free:") + 9, data.indexOf(" ")));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("ram_free").innerHTML = Math.round(data.substring(data.indexOf("ram_free:") + 9, data.indexOf(" ")));
|
||||||
document.getElementById("ram_percent_used").innerHTML = data.substring(data.indexOf("ram_percent_used:") + 17, data.indexOf(" "));
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("ram_percent_used").innerHTML = data.substring(data.indexOf("ram_percent_used:") + 17, data.indexOf(" "));
|
||||||
document.getElementById("disk_total").innerHTML = parseFloat(data.substring(data.indexOf("disk_total:") + 11, data.indexOf(" "))).toFixed(3);
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("disk_total").innerHTML = parseFloat(data.substring(data.indexOf("disk_total:") + 11, data.indexOf(" "))).toFixed(3);
|
||||||
document.getElementById("disk_used").innerHTML = parseFloat(data.substring(data.indexOf("disk_used:") + 10, data.indexOf(" "))).toFixed(3);
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("disk_used").innerHTML = parseFloat(data.substring(data.indexOf("disk_used:") + 10, data.indexOf(" "))).toFixed(3);
|
||||||
document.getElementById("disk_free").innerHTML = parseFloat(data.substring(data.indexOf("disk_free:") + 10, data.indexOf(" "))).toFixed(3);
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
data = data.substring(data.indexOf(" ") + 1);
|
document.getElementById("disk_free").innerHTML = parseFloat(data.substring(data.indexOf("disk_free:") + 10, data.indexOf(" "))).toFixed(3);
|
||||||
document.getElementById("disk_percent_used").innerHTML = data.substring(data.indexOf("disk_percent_used:") + 18);
|
data = data.substring(data.indexOf(" ") + 1);
|
||||||
|
document.getElementById("disk_percent_used").innerHTML = data.substring(data.indexOf("disk_percent_used:") + 18);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
logtailer.py
23
logtailer.py
|
@ -13,7 +13,7 @@ import os
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
from ansi2html import Ansi2HTMLConverter
|
from ansi2html import Ansi2HTMLConverter
|
||||||
from gpiozero import CPUTemperature
|
#from gpiozero import CPUTemperature
|
||||||
from os import popen
|
from os import popen
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
@ -112,9 +112,21 @@ def view_log(websocket, path):
|
||||||
yield from asyncio.sleep(0.2)
|
yield from asyncio.sleep(0.2)
|
||||||
elif path == "/SYSINFO":
|
elif path == "/SYSINFO":
|
||||||
while True:
|
while True:
|
||||||
cpu = CPUTemperature()
|
# cpu = CPUTemperature()
|
||||||
f = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
|
# cpu_temp = psutil.sensors_temperatures()
|
||||||
cpufrq = str((int(f.read()) / 1000))
|
cpu_temp = ""
|
||||||
|
temps = psutil.sensors_temperatures()
|
||||||
|
if not temps:
|
||||||
|
cpu_temp = "N/A"
|
||||||
|
for name, entries in temps.items():
|
||||||
|
for entry in entries:
|
||||||
|
cpu_temp = str(entry.current)
|
||||||
|
# f = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
|
||||||
|
cpufrqs = psutil.cpu_freq()
|
||||||
|
cpufrq = "N/A"
|
||||||
|
if cpufrqs:
|
||||||
|
cpufrq = str(cpufrqs.current)
|
||||||
|
# cpufrq = str((int(f.read()) / 1000))
|
||||||
cpu_usage = str(psutil.cpu_percent())
|
cpu_usage = str(psutil.cpu_percent())
|
||||||
cpu_load = os.getloadavg();
|
cpu_load = os.getloadavg();
|
||||||
cpu_load1 = str(cpu_load[0])
|
cpu_load1 = str(cpu_load[0])
|
||||||
|
@ -132,7 +144,8 @@ def view_log(websocket, path):
|
||||||
disk_used = str(disk.used / 2**30)
|
disk_used = str(disk.used / 2**30)
|
||||||
disk_free = str(disk.free / 2**30)
|
disk_free = str(disk.free / 2**30)
|
||||||
disk_percent_used = str(disk.percent)
|
disk_percent_used = str(disk.percent)
|
||||||
yield from websocket.send("SYSINFO: cputemp:" + str(cpu.temperature) + " cpufrg:" + cpufrq + " cpuusage:" + cpu_usage + " cpu_load1:" + cpu_load1 + " cpu_load5:" + cpu_load5 + " cpu_load15:" + cpu_load15 + " ram_total:" + ram_total + " ram_used:" + ram_used + " ram_free:" + ram_free + " ram_percent_used:" + ram_percent_used + " disk_total:" + disk_total + " disk_used:" + disk_used + " disk_free:" + disk_free + " disk_percent_used:" + disk_percent_used)
|
yield from websocket.send("SYSINFO: cputemp:" + cpu_temp + " cpufrg:" + cpufrq + " cpuusage:" + cpu_usage + " cpu_load1:" + cpu_load1 + " cpu_load5:" + cpu_load5 + " cpu_load15:" + cpu_load15 + " ram_total:" + ram_total + " ram_used:" + ram_used + " ram_free:" + ram_free + " ram_percent_used:" + ram_percent_used + " disk_total:" + disk_total + " disk_used:" + disk_used + " disk_free:" + disk_free + " disk_percent_used:" + disk_percent_used)
|
||||||
|
# yield from websocket.send("SYSINFO: cputemp:" + str(cpu.temperature) + " cpufrg:" + cpufrq + " cpuusage:" + cpu_usage + " cpu_load1:" + cpu_load1 + " cpu_load5:" + cpu_load5 + " cpu_load15:" + cpu_load15 + " ram_total:" + ram_total + " ram_used:" + ram_used + " ram_free:" + ram_free + " ram_percent_used:" + ram_percent_used + " disk_total:" + disk_total + " disk_used:" + disk_used + " disk_free:" + disk_free + " disk_percent_used:" + disk_percent_used)
|
||||||
yield from asyncio.sleep(10)
|
yield from asyncio.sleep(10)
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
|
Loading…
Reference in a new issue