improved lh, added sysinfo

This commit is contained in:
dg9vh 2016-04-30 19:33:41 +02:00
parent 6293153ba4
commit 38e5e8eb30
6 changed files with 180 additions and 3 deletions

View file

@ -5,4 +5,7 @@ define("LOGPATH","/mnt/ramdisk/");
define("LOGPREFIX","MMDVM");
define("LOGFILE",LOGPATH . LOGPREFIX . "-" . date("Y-m-d") . ".log");
define("REFRESHAFTER","60");
define("TEMPERATUREALERT",true);
define("TEMPERATUREHIGHLEVEL", 60);
define("SHOWPROGRESSBARS", true);
?>

View file

@ -3,6 +3,7 @@
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
// M: 2016-04-29 00:15:00.013 D-Star, received network header from DG9VH /ZEIT to CQCQCQ via DCS002 S
// M: 2016-04-29 19:43:21.839 DMR Slot 2, received network voice header from DL1ESZ to TG 9
// M: 2016-04-30 14:57:43.072 DMR Slot 2, received RF voice header from DG9VH to 5000
function getLastHeard() {
$lastHeard = array();
@ -24,9 +25,13 @@ function getLastHeard() {
$id = substr($callsign2, strpos($callsign2,"/") + 1);
}
$target = substr($logLine, strpos($logLine, "to") + 3);
$source = "RF";
if (strpos($logLine,"network") > 0 ) {
$source = "Network";
}
if ( strlen($callsign <7) ) {
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target));
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source));
}
//Last-Heard-Liste: Array aufbauen in umgekehrter Richtung des Logs
//Zeilen ausblenden, bei denen das Callsign länger als 6 Stellen ist
@ -35,8 +40,8 @@ function getLastHeard() {
}
array_multisort($heardList,SORT_DESC);
foreach ($heardList as $listElem) {
if(!(array_search($listElem[2], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]);
if(!(array_search($listElem[2]."#".$listElem[1].$listElem[3], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]."#".$listElem[1].$listElem[3]);
array_push($lastHeard, $listElem);
}
}

View file

@ -16,6 +16,7 @@ $lastHeard = getLastHeard();
<th>Callsign</th>
<th>DSTAR-ID</th>
<th>Target</th>
<th>Source</th>
</tr>
<?php
foreach ($lastHeard as $listElem) {
@ -26,6 +27,7 @@ foreach ($lastHeard as $listElem) {
echo"<td>$listElem[2]</td>";
echo"<td>$listElem[3]</td>";
echo"<td>$listElem[4]</td>";
echo"<td>$listElem[5]</td>";
echo"</tr>";
}

138
include/sysinfo.php Normal file
View file

@ -0,0 +1,138 @@
<?php
exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
$cputemp = $cputemp[0] / 1000;
if (TEMPERATUREALERT && $cputemp > TEMPERATUREHIGHLEVEL) {
?>
<script>
function deleteLayer(id) {
if (document.getElementById && document.getElementById(id)) {
var theNode = document.getElementById(id);
theNode.parentNode.removeChild(theNode);
}
else if (document.all && document.all[id]) {
document.all[id].innerHTML='';
document.all[id].outerHTML='';
}
// OBSOLETE CODE FOR NETSCAPE 4
else if (document.layers && document.layers[id]) {
document.layers[id].visibility='hide';
delete document.layers[id];
}
}
function makeLayer(id,L,T,W,H,bgColor,visible,zIndex) {
if (document.getElementById) {
if (document.getElementById(id)) {
alert ('Layer with this ID already exists!');
return;
}
var ST = 'position:absolute; text-align:center;padding-top:20px;'
+'; left:'+L+'px'
+'; top:'+T+'px'
+'; width:'+W+'px'
+'; height:'+H+'px'
+'; clip:rect(0,'+W+','+H+',0)'
+'; visibility:'
+(null==visible || 1==visible ? 'visible':'hidden')
+(null==zIndex ? '' : '; z-index:'+zIndex)
+(null==bgColor ? '' : '; background-color:'+bgColor);
var LR = '<DIV id='+id+' style="'+ST+'">CPU-Temerature is very high!<br><input type="button" value="Close" onclick="deleteLayer(\'LYR1\')"></DIV>';
if (document.body) {
if (document.body.insertAdjacentHTML)
document.body.insertAdjacentHTML("BeforeEnd",LR);
else if (document.createElement && document.body.appendChild) {
var newNode = document.createElement('div');
newNode.setAttribute('id',id);
newNode.setAttribute('style',ST);
document.body.appendChild(newNode);
}
}
}
}
var audio = new Audio('sounds/alert.mp3');
audio.play();
var x = window.innerWidth/2-100;
var y = window.innerHeight/2-50;
makeLayer('LYR1',x,y,200,100,'red',1,1);
</script>
<?php
}
$cpufreq = $cpufreq[0] / 1000;
$output = shell_exec('cat /proc/loadavg');
$sysload = substr($output,0,strpos($output," "))*100;
$stat1 = file('/proc/stat');
sleep(1);
$stat2 = file('/proc/stat');
$info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0]));
$info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0]));
$dif = array();
$dif['user'] = $info2[0] - $info1[0];
$dif['nice'] = $info2[1] - $info1[1];
$dif['sys'] = $info2[2] - $info1[2];
$dif['idle'] = $info2[3] - $info1[3];
$total = array_sum($dif);
$cpu = array();
foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
$cpuusage = round($cpu['user'] + $cpu['sys'], 2);
$output = shell_exec('grep -c processor /proc/cpuinfo');
$cpucores = $output;
$output = shell_exec('cat /proc/uptime');
$uptime = format_time(substr($output,0,strpos($output," ")));
$idletime = format_time((substr($output,strpos($output," ")))/$cpucores);
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">System Info</div>
<div class="panel-body">
<p>In the following table you find some important system information</p>
</div>
<!-- Tabelle -->
<table class="table">
<tbody>
<tr>
<th>CPU-Temperature</th>
<th>CPU-Frequency</th>
<th>System-Load</th>
<th>CPU-Usage</th>
<th>Uptime</th>
<th>Idle</th>
</tr>
<tr class="gatewayinfo">
<td><?php echo $cputemp; ?> &deg;C</td>
<td><?php echo $cpufreq; ?> MHz</td>
<td><?php echo $sysload; ?> %</td>
<td>
<?php
if (SHOWPROGRESSBARS) {
?>
<div class="progress"><div class="progress-bar <?php
if ($cpuusage < 30)
echo "progress-bar-success";
if ($cpuusage >= 30 and $cpuusage < 60)
echo "progress-bar-warning";
if ($cpuusage >= 60)
echo "progress-bar-danger";
?>" role="progressbar" aria-valuenow="<?php echo $cpuusage; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $cpuusage; ?>%;"><?php echo $cpuusage; ?>%</div></div>
<?php
} else {
echo $cpuusage." %";
}
?>
</td>
<td><?php echo $uptime; ?></td>
<td><?php echo $idletime; ?></td>
</tr>
</tbody>
</table>
</div>

27
include/tools.php Normal file
View file

@ -0,0 +1,27 @@
<?php
function format_time($seconds) {
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString = "";
if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? "&nbsp;day" : "&nbsp;days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? "&nbsp;hour" : "&nbsp;hours");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? "&nbsp;minute" : "&nbsp;minutes");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? "&nbsp;second" : "&nbsp;seconds");
}
return $uptimeString;
}
?>

View file

@ -1,5 +1,6 @@
<?php
include "config/config.php";
include "include/tools.php";
include "include/functions.php";
?>
<!doctype html>
@ -24,6 +25,7 @@ include "include/functions.php";
<h1>MMDVM-Dashboard by DG9VH <small>Repeater: <?php echo REPEATERCALLSIGN?></small></h1>
</div>
<?php
include "include/sysinfo.php";
include "include/lh.php";
?>
<div class="panel panel-info">