Added SysInfo-Tab
closed https://github.com/dg9vh/MMDVMHost-Websocketboard/issues/10
This commit is contained in:
parent
ce35c1fcd0
commit
dd99558ca8
5 changed files with 125 additions and 27 deletions
|
@ -23,6 +23,7 @@ You'll need to install several python3 modules. A concrete list will follow here
|
|||
Actually known:
|
||||
* websockets: `sudo apt install python3-websockets`
|
||||
* ansi2html: `sudo pip3 install ansi2html`
|
||||
* gpiozero: `sudo apt install python3-gpiozero`
|
||||
|
||||
### Reommendations
|
||||
* take care to set Loglevel for FileLevel = 2 in your MMDVM.ini
|
||||
|
|
|
@ -52,6 +52,9 @@
|
|||
<li class="nav-item">
|
||||
<a class="nav-link" id="dapnet-tab" data-toggle="tab" href="#dapnet" role="tab" aria-controls="dapnet" aria-selected="false">DAPNET Messages</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="sysinfo-tab" data-toggle="tab" href="#sysinfo" role="tab" aria-controls="sysinfo" aria-selected="false">System Info</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="about-tab" data-toggle="tab" href="#about" role="tab" aria-controls="about" aria-selected="false">About</a>
|
||||
</li>
|
||||
|
@ -182,6 +185,27 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="sysinfo" role="tabpanel" aria-labelledby="sysinfo-tab">
|
||||
<div class="panel panel-default">
|
||||
<!-- Standard-Panel-Inhalt -->
|
||||
<div class="panel-heading">System Info<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span></div>
|
||||
<div class="panel-body">
|
||||
<ul>
|
||||
<li>CPU Temperature: <span id="cputemp"></span> °C</li>
|
||||
<li>CPU Frequency: <span id="cpufrg"></span> MHz</li>
|
||||
<li>CPU Usage: <span id="cpuusage"></span>%</li>
|
||||
<li>RAM Total: <span id="ram_total"></span> MB</li>
|
||||
<li>RAM Used: <span id="ram_used"></span> MB</li>
|
||||
<li>RAM Free: <span id="ram_free"></span> MB</li>
|
||||
<li>RAM Usage: <span id="ram_percent_used"></span> %</li>
|
||||
<li>Disk Total: <span id="disk_total"></span> GB</li>
|
||||
<li>Disk Used: <span id="disk_used"></span> GB</li>
|
||||
<li>Disk Free: <span id="disk_free"></span> GB</li>
|
||||
<li>Disk Usage: <span id="disk_percent_used"></span> %</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="about" role="tabpanel" aria-labelledby="about-tab">
|
||||
<div class="panel panel-default">
|
||||
<!-- Standard-Panel-Inhalt -->
|
||||
|
@ -215,6 +239,11 @@
|
|||
"order": [[ 0, "desc" ]]
|
||||
} );
|
||||
|
||||
var ws3 = new WebSocket("ws://" + window.location.hostname + ":5678/SYSINFO");
|
||||
ws3.onmessage = function (event) {
|
||||
getSysInfo(document, event);
|
||||
};
|
||||
|
||||
var ws1 = new WebSocket("ws://" + window.location.hostname + ":5678/MMDVM");
|
||||
ws1.onmessage = function (event) {
|
||||
getLastHeard(document, event);
|
||||
|
@ -246,6 +275,7 @@
|
|||
getDapnetMessages(document, event);
|
||||
};
|
||||
t_dapnet.order( [ 0, 'desc' ] ).draw();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -15,8 +15,9 @@ var showLastHeardTab = 1;
|
|||
var showLocalHeadTab = 1;
|
||||
var showInQSOTab = 1;
|
||||
var showDAPNETMessagesTab = 1;
|
||||
var showSysInfoTab = 1;
|
||||
var showAboutTab = 1;
|
||||
|
||||
// default-tab to show
|
||||
// chose from following list: CurrTXTab, LastHeardTab, LocalHeadTab, InQSOTab, DAPNETMessagesTab, AboutTab
|
||||
// chose from following list: CurrTXTab, LastHeardTab, LocalHeadTab, InQSOTab, DAPNETMessagesTab, SysInfoTab, AboutTab
|
||||
var defaultTab = "LastHeardTab";
|
|
@ -450,6 +450,37 @@ function getDapnetMessages(document, event) {
|
|||
});
|
||||
}
|
||||
|
||||
function getSysInfo(document, event) {
|
||||
$(document).ready(function() {
|
||||
// cputemp:49.388 cpufrg:600.0 cpuusage:0.8 ram_total:974.37890625 ram_used:159.69140625 ram_free:157.265625 ram_percent_used:27.9 disk_total:7.084514617919922 disk_used:3.5408592224121094 disk_free:3.2069854736328125 disk_percent_used:52.5
|
||||
logIt(event.data);
|
||||
data = event.data;
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
logIt(data);
|
||||
document.getElementById("cputemp").innerHTML = parseFloat(data.substring(data.indexOf("cputemp:") + 8, data.indexOf(" "))).toFixed(1);
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("cpufrg").innerHTML = data.substring(data.indexOf("cpufrg:") + 7, data.indexOf(" "));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("cpuusage").innerHTML = data.substring(data.indexOf("cpuusage:") + 9, data.indexOf(" "));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("ram_total").innerHTML = Math.round(data.substring(data.indexOf("ram_total:") + 10, data.indexOf(" ")));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("ram_used").innerHTML = Math.round(data.substring(data.indexOf("ram_used:") + 9, data.indexOf(" ")));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("ram_free").innerHTML = Math.round(data.substring(data.indexOf("ram_free:") + 9, data.indexOf(" ")));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("ram_percent_used").innerHTML = data.substring(data.indexOf("ram_percent_used:") + 17, data.indexOf(" "));
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("disk_total").innerHTML = parseFloat(data.substring(data.indexOf("disk_total:") + 11, data.indexOf(" "))).toFixed(3);
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("disk_used").innerHTML = parseFloat(data.substring(data.indexOf("disk_used:") + 10, data.indexOf(" "))).toFixed(3);
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("disk_free").innerHTML = parseFloat(data.substring(data.indexOf("disk_free:") + 10, data.indexOf(" "))).toFixed(3);
|
||||
data = data.substring(data.indexOf(" ") + 1);
|
||||
document.getElementById("disk_percent_used").innerHTML = data.substring(data.indexOf("disk_percent_used:") + 18);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
if(showCurrTXTab == 0){
|
||||
document.getElementById("myTab").children[0].style.display="none";
|
||||
|
@ -471,8 +502,12 @@ $(document).ready(function() {
|
|||
document.getElementById("myTab").children[4].style.display="none";
|
||||
document.getElementById("dapnet").style.display="none";
|
||||
}
|
||||
if(showAboutTab == 0){
|
||||
if(showSysInfoTab == 0){
|
||||
document.getElementById("myTab").children[5].style.display="none";
|
||||
document.getElementById("sysinfo").style.display="none";
|
||||
}
|
||||
if(showAboutTab == 0){
|
||||
document.getElementById("myTab").children[6].style.display="none";
|
||||
document.getElementById("about").style.display="none";
|
||||
}
|
||||
|
||||
|
@ -516,6 +551,14 @@ $(document).ready(function() {
|
|||
element.classList.add("show");
|
||||
element.classList.add("active");
|
||||
break;
|
||||
case "SysInfoTab":
|
||||
var element = document.getElementById("sysinfo-tab");
|
||||
element.classList.add("active");
|
||||
|
||||
var element = document.getElementById("sysinfo");
|
||||
element.classList.add("show");
|
||||
element.classList.add("active");
|
||||
break;
|
||||
case "AboutTab":
|
||||
var element = document.getElementById("about-tab");
|
||||
element.classList.add("active");
|
||||
|
|
23
logtailer.py
23
logtailer.py
|
@ -13,6 +13,9 @@ import os
|
|||
from collections import deque
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
from ansi2html import Ansi2HTMLConverter
|
||||
from gpiozero import CPUTemperature
|
||||
from os import popen
|
||||
import psutil
|
||||
|
||||
current_dir = os.getcwd()
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -53,6 +56,7 @@ def view_log(websocket, path):
|
|||
elif path == "/DAPNET":
|
||||
file_path = config['DAPNETGateway']['Logdir']+config['DAPNETGateway']['Prefix']+"-"+year+"-"+month+"-"+day+".log"
|
||||
NUM_LINES = 0
|
||||
if path == "/MMDVM" or path == "/DAPNET":
|
||||
logging.info(file_path)
|
||||
if not os.path.isfile(file_path):
|
||||
raise ValueError('File not found', format(file_path))
|
||||
|
@ -82,6 +86,25 @@ def view_log(websocket, path):
|
|||
yield from websocket.send(line)
|
||||
else:
|
||||
yield from asyncio.sleep(0.2)
|
||||
elif path == "/SYSINFO":
|
||||
while True:
|
||||
cpu = CPUTemperature()
|
||||
f = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
|
||||
cpufrq = str((int(f.read()) / 1000))
|
||||
cpu_usage = str(psutil.cpu_percent())
|
||||
ram = psutil.virtual_memory()
|
||||
ram_total = str(ram.total / 2**20)
|
||||
ram_used = str(ram.used / 2**20)
|
||||
ram_free = str(ram.free / 2**20)
|
||||
ram_percent_used = str(ram.percent)
|
||||
|
||||
disk = psutil.disk_usage('/')
|
||||
disk_total = str(disk.total / 2**30)
|
||||
disk_used = str(disk.used / 2**30)
|
||||
disk_free = str(disk.free / 2**30)
|
||||
disk_percent_used = str(disk.percent)
|
||||
yield from websocket.send("SYSINFO: cputemp:" + str(cpu.temperature) + " cpufrg:" + cpufrq + " cpuusage:" + cpu_usage + " 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)
|
||||
|
||||
except ValueError as e:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue