Skip to content

Instantly share code, notes, and snippets.

@andrewchumchal
Last active December 20, 2018 20:17
Show Gist options
  • Save andrewchumchal/2807178434052081f4a694561a41358f to your computer and use it in GitHub Desktop.
Save andrewchumchal/2807178434052081f4a694561a41358f to your computer and use it in GitHub Desktop.
<?php error_reporting(0);
$page = $_SERVER['PHP_SELF']; //For Auto refresh
$sec = "30"; //For Auto refresh
$down = "<h7 class='redtext'> DOWN</h7>";
$dockerIP = "192.168.1.2";
$apps = array("cAdvisor", "Guacamole", "PlexMediaServer", "PlexPy", "PlexRequest", "Tranmission", "FlexGet", "CouchPotato", "SickRage");
$ports = array(8081, 8080, 32400, 8181, 3000, 9091, 3539, 5050, 8083);
$timeoutsec = 10;
$totalapps = count($apps);
function pingPort($host, $port, $timeout){
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "<h7 class='redtext'> DOWN</h7>"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms";
}
//DockerCheck
// echo pingPort($dockerIP, $ports[0], $timeoutsec);
$unraidPing = pingPort($dockerIP, 80, 10);
$cAdvisorPing = pingPort($dockerIP, 8081, 10);
$gucamolePing = pingPort($dockerIP, 8080, 10);
$plexMediaServerPing = pingPort($dockerIP, 32400, 10);
$plexPyPing = pingPort($dockerIP, 8181, 10);
$plexReguestPing = pingPort($dockerIP, 3000, 10);
$transmissionPing = pingPort($dockerIP, 9091, 10);
$flexGetPing = pingPort($dockerIP, 3539, 10);
$couchPotatoPing = pingPort($dockerIP, 5050, 10);
$sickRagePing = pingPort($dockerIP, 8083, 10);
// Aaron's Code
// Create a Dictionary
$portsAndStatus = [];
for($i = 0; $i < count($apps); $i++){
$portsAndStatus[$apps[$i]] = pingPort($dockerIP, $ports[$i], 10);
}
//
?>
<!DOCTYPE html>
<html>
<head>
<title> Is it up?</title>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'"> <!-- Auto Refresh -->
<style type="text/css">
table, th, td {
border: 1px solid black;
}
.redtext {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<table style="width:25%">
<tr>
<th>Dockername</th>
<th>Pingtime</th>
</tr>
<tr>
<td>unRaid Server</td>
<td><?php echo $unraidPing; ?></td>
</tr>
<?php
// print not downed ports
foreach ($portsAndStatus as $key => $value) {
if($value != $down){
?>
<tr>
<td> <?php echo $key; ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php
}
}
// print downed ports
foreach ($portsAndStatus as $key => $value) {
if($value == $down){
?>
<tr>
<td> <?php echo $key; ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php
}
}
?>
</table>
<br>
</body>
</html>
@divinity76
Copy link

divinity76 commented Dec 20, 2018

hol up, you never close the connection! every time you call pingport(), php creates a new connection, that it never closes (well, the OS will probably close it once php has exited, but still) make that

      if (!$fP) { return "<h7 class='redtext'> DOWN</h7>"; } else {
          fclose($fP);
      }
      $tA = microtime(true); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment