ezservermonitor-web/libs/disk.php
HBadertscher 80b48185d3 Adds option to ignore mounts via config file
This allows you to configure eZ Server Monitor to ignore certain disks
via the "ignore_mounts" option in the configuration file. You can either
create no "ignore_mounts" option at all, or set it to [] if you want to
show all mounts. To ignore certain mounts, add the exact mount path to
the array, e.g. ["/mnt/disk1"] or ["/mnt/disk1", "/mnt/disk2"].
This is done with *exact* string matching, so make sure the entries are
correct. This makes it possible to ignore "/" and still show other
paths.
2017-11-01 11:23:21 +01:00

64 lines
1.8 KiB
PHP

<?php
require '../autoload.php';
$Config = new Config();
$datas = array();
# if there are more than 7 awk's colums it means the mount point name contains spaces
# so consider the first colums as a unique colum and the last 6 as real colums
if (!(exec('/bin/df -T -P | tail -n +2 | awk \'{ if (NF > 7) { for (i=1; i<NF-6; i++) { printf("%s ", $i); } for (i=NF-6; i<NF; i++) { printf("%s,", $i); } print $NF; } else { print $1","$2","$3","$4","$5","$6","$7; } }\'', $df)))
{
$datas[] = array(
'total' => 'N.A',
'used' => 'N.A',
'free' => 'N.A',
'percent_used' => 0,
'mount' => 'N.A',
'filesystem' => 'N.A',
);
}
else
{
$mounted_points = array();
$key = 0;
foreach ($df as $mounted)
{
list($filesystem, $type, $total, $used, $free, $percent, $mount) = explode(',', $mounted);
if ($percent > 100)
$percent = 100;
if (strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false)
continue;
foreach ($Config->get('disk:ignore_mounts') as $to_ignore)
{
if ($mount === $to_ignore)
continue 2;
}
if (!in_array($mount, $mounted_points))
{
$mounted_points[] = trim($mount);
$datas[$key] = array(
'total' => Misc::getSize($total * 1024),
'used' => Misc::getSize($used * 1024),
'free' => Misc::getSize($free * 1024),
'percent_used' => trim($percent, '%'),
'mount' => $mount,
);
if ($Config->get('disk:show_filesystem'))
$datas[$key]['filesystem'] = $filesystem;
}
$key++;
}
}
echo json_encode($datas);