Skip to content

Instantly share code, notes, and snippets.

@digibart
Last active November 25, 2022 14:14
Show Gist options
  • Save digibart/c50ed8b23a314dc69066 to your computer and use it in GitHub Desktop.
Save digibart/c50ed8b23a314dc69066 to your computer and use it in GitHub Desktop.
A simple status page of running services, http://spatula.pixelbak.nl/grill.php
<html>
<head>
<title>Grill</title>
<style>
body {
background: #f7f7f7;
width: 500px;
margin: 0 auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.1em;
padding: 1.1em;
}
td
{
border: none;
padding: .5em;
}
table {
background: #fff;
color: #222;
font-size: 1em;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}
h2 {
margin: 1em 0 0 0;
padding: .5em 0;
font-size: 1.5em;
color: #fff;
background: #222;
text-align: center;
width: 100%;
}
.label {
padding: 1px 8px 2px 8px;
border-radius: 50px;
font-size: .9em;
box-shadow: 1px 1px 3px rgba(0,0,0,.2);
}
.label.online {
background: #14CC22;
border: solid 1px #109C1B;
}
.label.offline {
background: #ff2e00;
border: solid 1px #BF2300;
color: #fff;
box-shadow: 2px 2px 10px #ff3400
}
.box.info {
background: #00cd0a;
color: black;
border-radius: 3px;
padding: 5px 7px;
margin: 15px 0;
text-shadow: 1px 1px 2px rgba(255,255,255,.5);
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<H2>Service Status</H2>
<?php
//configure script
$timeout = "1";
$count = 0;
$online = 0;
$services = array(
array('port' => 80, 'service' => 'Apache'),
array('port' => 21, 'service' => 'FTP'),
array('port' => 3306, 'service' => 'MySQL', 'host' => 'localhost'),
array('port' => 25, 'service' => 'SMTP'),
array('port' => 143, 'service' => 'IMAP'),
array('port' => 80, 'service' => 'Outward connection', 'host' => 'google.com')
);
$data = "<table width='100%' align='center'>";
foreach ($services as $service)
{
if (!isset($service['host']) || empty($service['host']))
{
$service['host'] = $_SERVER['HTTP_HOST'];
}
$fp = @fsockopen($service['host'], $service['port'], $errno, $errstr, $timeout);
if (!$fp)
{
$data .= "<tr><td>" . $service['service'] . "</td><td><span class='label offline'>Offline</span></td></tr>";
fclose($fp);
} else
{
$data .= "<tr><td>" . $service['service'] . "</td><td><span class='label online'>Online</span></td></tr>";
$online++;
fclose($fp);
}
$count++;
}
$data .= "</table>";
echo $data;
if ($online == count($services)) {
echo "<div class='box info'>The oven is preheated. Please insert your pie.</div>";
}
?>
<H2>Server Information</H2>
<?php
$data1 = "<table width='100%' align='center'>";
//GET SERVER LOADS
$loadresult = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $loadresult, $avgs);
//GET DISK USAGE
$diskusage = @exec(" df -h / | tail -n 1 | awk '{ print $5 }'");
//GET SERVER UPTIME
$uptime = explode(' up ', $loadresult);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
$data1 .= "<tr><td>Server Load Averages </td><td>$avgs[1], $avgs[2], $avgs[3]</td>\n";
$data1 .= "<tr><td>Server Uptime </td><td>$uptime </td></tr>";
/* $data1 .= "<tr><td>Disk Usage </td><td>$diskusage </td></tr>"; */
$data1 .= "</table>";
echo $data1;
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment