monitoring/libs/disk.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2023-02-25 01:06:41 +00:00
<?php
require '../autoload.php';
$Config = new Config();
$datas = array();
if (!(exec('/bin/df -T | awk -v c=`/bin/df -T | grep -bo "Type" | awk -F: \'{print $2}\'` \'{print substr($0,c);}\' | tail -n +2 | awk \'{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 (strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false)
continue;
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);