Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

106 lines (97 sloc) 3.259 kb
<?php
error_reporting(E_ALL ^ E_NOTICE);
include 'config/phpconf.php';
$mach_id = $_GET['mach_id'];
function getDisks($dir, $mach_id){
$xml = simplexml_load_file("config/disk.conf");
foreach($xml->children() as $child){
$disk_id = 0;
foreach($child->children() as $att){
if($att->getName() == "disk_id")
$disk_id = $att;
elseif($att->getName() == "red")
$red_map[intval($disk_id)] = intval($att);
elseif($att->getName() == "yellow")
$yellow_map[intval($disk_id)] = intval($att);
}
}
#DISKS
$dbh = new PDO($dir) or die("cannot open the database");
$sql = 'SELECT * FROM disk WHERE mach_id=:mach_id';
$stmt = $dbh->prepare($sql);
$stmt->execute(array(':mach_id'=>$mach_id));
foreach ($stmt->fetchAll() as $disk){
$disk_id = $disk[0];
$sql = 'SELECT * FROM diskusage WHERE disk_id=? ORDER BY time DESC LIMIT 1';
$stmt2 = $dbh->prepare($sql);
$stmt2->bindParam(1, $disk_id, PDO::PARAM_INT);
$stmt2->execute();
$usage = $stmt2->fetch();
$timestamp = $usage[2];
$size = intval($usage[3]);
$used = intval($usage[4]);
$device = $disk[2];
$mnt = $disk[3];
try{
$red = $red_map[intval($disk_id)];
$yellow = $yellow_map[intval($disk_id)];
}catch (Exception $e){}
echo '<tr class="disk_clickable" id="'.$disk_id.'">';
if($red == NULL || $yellow == NULL)
echo '<td class="green"></td>';
elseif($used > $red)
echo '<td class="red"></td>';
elseif($used > $yellow)
echo '<td class="yellow"></td>';
else
echo '<td class="green"></td>';
echo '<td class="highlight">'.$device.'</td>';
if($size > 1048576)
echo '<td class="highlight">'.round(($size/1048576),2).' GB</td>';
else
echo '<td class="highlight">'.round(($size/1024), 2).' MB</td>';
echo '<td class="highlight">'.$used.'%</td>';
echo '<td class="highlight">'.$mnt.'</td>';
echo '<td class="highlight">'.date('Y:m:d H:i:s', $timestamp).'</td>';
echo '</tr>';
}
}
?>
<table id="disks_table" class="tablesorter">
<thead>
<tr>
<th>Status</th>
<th>Device</th>
<th>Size</th>
<th>Used</th>
<th>Mount</th>
<th>Last changed (UTC)</th>
</tr>
</thead>
<tbody>
<?php echo getDisks($dir, $mach_id); ?>
</tbody>
</table>
<script type="text/javascript">
$("#plot_disk_button").button({ disabled: true });
$("tr.disk_clickable").off("click");
$("tr.disk_clickable").on("click", function(){
$("#plot_disk_button").button({ disabled: false });
$("tr.disk_clickable").removeClass("clicked");
$(this).addClass("clicked");
var id = $(this).attr("id");
$("#plot_disk_button").off("click");
$("#plot_disk_button").on("click", function(){
$.fancybox.showLoading();
var start = $("#datepicker_start").datepicker("getDate");
var end = $("#datepicker_end").datepicker("getDate");
var start_epoch = parseInt($("#start").val()) / 1000;
var end_epoch = parseInt($("#end").val()) / 1000 + 24*60*60;
var args = "type=disk&disk_id=" + id + "&start=" + start_epoch + "&end=" + end_epoch;
$.get("plot.php?" + args, function(data) {
$.fancybox.open("images/plot.png?no-cache=" + new Date().getTime(), {padding:0});
});
});
});
$("tr.disk_clickable:first").trigger("click");
</script>
Jump to Line
Something went wrong with that request. Please try again.