Created
May 18, 2015 04:41
-
-
Save 128keaton/6fbd0980687d8c56f137 to your computer and use it in GitHub Desktop.
Temperature monitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//add your server aliases here | |
$servers = array( | |
"10.0.0.201" => "Larry", | |
"10.0.0.56" => "Le Mac Pro", | |
); | |
if(isset( $_POST['temp'], $_POST['df'] )){ | |
preg_match('/\d+\.\d{2}/', $_POST['temp'],$temp); | |
preg_match('/\d+%/', $_POST['df'],$df); | |
$stats = array( | |
"temp" => $temp[0], | |
"ip" => $_SERVER["REMOTE_ADDR"] | |
); | |
save_to_stats($stats); | |
}else{ | |
output_stats_table(); | |
echo "empty"; | |
echo "<table>"; | |
foreach ($_POST as $key => $value) { | |
echo "<tr>"; | |
echo "<td>"; | |
echo $key; | |
echo "</td>"; | |
echo "<td>"; | |
echo $value; | |
echo "</td>"; | |
echo "</tr>"; | |
} | |
echo "</table>"; | |
} | |
function save_to_stats($stats){ | |
$data = json_decode( file_get_contents("temps.json"), true ); | |
$data[ $stats['ip'] ] = $stats; | |
file_put_contents("stats.json", json_encode($data), LOCK_EX); | |
} | |
function output_stats_table(){ | |
global $servers; | |
//display data | |
$data = json_decode( file_get_contents("temps.json"), true ); | |
?> | |
<table id="projects"> | |
<?php foreach($data as $server => $stats): ?> | |
<tr> | |
<td class="server-status" style="width:48px;" ><?php if (time() - (int) $stats['time'] > $timeinsecondstoalert ) | |
{ | |
} | |
else | |
{ | |
} ?></td> | |
<td class="server-name" style="width:200px; text-transform:lowercase;"><?php echo $servers[$stats['ip']] ; ?></td> | |
<td class="server-load" style="width:72px;"><?php echo $servers[$stats['temp']] ; ?></td> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
<?php | |
}; | |
function number_of_bars($df){ | |
$value = (int) str_replace('%', '', $df) / 10; | |
return round( ($value > 8 ? 8 : $value) * .8 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment