%PDF- %PDF-
| Direktori : /usr/share/l.v.e-manager/interworx/lvemanager/Ctrl/Siteworx/ |
| Current File : //usr/share/l.v.e-manager/interworx/lvemanager/Ctrl/Siteworx/ResourceDetails.php |
<?php
/**
* Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
*
* Licensed under CLOUD LINUX LICENSE AGREEMENT
* http://cloudlinux.com/docs/LICENSE.TXT
*/
include('roundMemB.php');
class Ctrl_Siteworx_ResourceDetails extends Ctrl_Siteworx_Plugin {
public function indexAction()
{
$uid = IW::SW()->getuid();
// period post
if(isset($_POST['period']))
{
$periodGet = $_POST['period'];
if($periodGet == '10m')
{
$period = '10m';
}
elseif($periodGet == '30m')
{
$period = '30m';
}
elseif($periodGet == '1h')
{
$period = '1h';
}
elseif($periodGet == '4h')
{
$period = '4h';
}
elseif($periodGet == '1d')
{
$period = '1d';
}
elseif($periodGet == 'today')
{
$period = 'today';
}
elseif($periodGet == 'yesterday')
{
$period = 'yesterday';
}
elseif($periodGet == '7d')
{
$period = '7d';
}
elseif($periodGet == '30d')
{
$period = '30d';
}
else
{
$period = '1d';
}
}
else
{
$period = '1d';
}
// open lve info
$lveinfo = file("/var/lve/info");
$lveinfoResultOk = 0;
foreach ($lveinfo as $line_num => $line)
{
$lveTmp = explode(',', $line);
if($lveTmp[0] == $uid)
{
$MEP_INDEX = $lveTmp[1];
$LEP_INDEX = $lveTmp[2];
$CPU_INDEX = $lveTmp[3];
$LCPU_INDEX = $lveTmp[4];
$MEM_INDEX = $lveTmp[5];
$LMEM_INDEX = $lveTmp[6];
$MEMF_INDEX = $lveTmp[7];
$MEPF_INDEX = $lveTmp[8];
// mark result OK
$lveinfoResultOk = 1;
}
}
if($lveinfoResultOk == 0)
{
$MEP_INDEX = '0';
$LEP_INDEX = '0';
$CPU_INDEX = '0';
$LCPU_INDEX = '0';
$MEM_INDEX = '0';
$LMEM_INDEX = '0';
$MEMF_INDEX = '';
$MEPF_INDEX = '';
}
$cpuUsage = ceil(@($CPU_INDEX / $LCPU_INDEX) * 100);
$memUsage = ceil(@($MEM_INDEX / $LMEM_INDEX) * 100);
$procUsage = ceil(@($MEP_INDEX / $LEP_INDEX) * 100);
include('veProcParser.php');
$veProcParser = veProcParser();
if(isset($veProcParser[$uid]))
{
$lcpu = $veProcParser[$uid]['lCPU'];
$lmem = $veProcParser[$uid]['lMEM'];
$lep = $veProcParser[$uid]['lEP'];
$lncpu = $veProcParser[$uid]['nCPU'];
}
else
{
$lcpu = $veProcParser[0]['lCPU'];
$lmem = $veProcParser[0]['lMEM'];
$lep = $veProcParser[0]['lEP'];
$lncpu = $veProcParser[0]['nCPU'];
}
ob_start();
passthru("/usr/sbin/lveinfo --csv --period=$period --id=$uid");
$lveInfoTmp = ob_get_contents();
ob_end_clean();
$lveInfoDet = array();
$lveInfoDetTmp = array();
$lveInfoAr = explode(chr(10), $lveInfoTmp);
$start = 0;
foreach ($lveInfoAr as $lveInfoVal)
{
if($start > 0)
{
$lveInfoDetTmp = explode(',', $lveInfoVal);
if(strlen($lveInfoDetTmp[0]) > 0)
{
if($lveInfoDetTmp[4] == 0)
{
$lveInfoDetTmp[4] = 100;
}
$apcpu = ceil( $lveInfoDetTmp[2] * 100 / $lveInfoDetTmp[4]);
$mpcpu = ceil( $lveInfoDetTmp[3] * 100 / $lveInfoDetTmp[4]);
$lveInfoDetTmp[2] = $apcpu;
$lveInfoDetTmp[3] = $mpcpu;
$lveInfoDetTmp[8] = roundMemB($lveInfoDetTmp[8]);
$lveInfoDetTmp[9] = roundMemB($lveInfoDetTmp[9]);
$lveInfoDetTmp[10] = roundMemB($lveInfoDetTmp[10]);
$lveInfoDet[$start] = $lveInfoDetTmp;
}
}
$start++;
}
$this->getView()->assign( 'title', 'Resource Usage Details' );
$this->getView()->assign( 'template', 'user/details' );
$this->getView()->assign( 'cpuUsage', $cpuUsage );
$this->getView()->assign( 'memUsage', $memUsage );
$this->getView()->assign( 'procUsage', $procUsage );
$this->getView()->assign( 'lcpu', $lcpu );
$this->getView()->assign( 'lmem', $lmem );
$this->getView()->assign( 'lmemround', roundMemB($lmem * 4096) );
$this->getView()->assign( 'mem_cur', roundMemB($MEM_INDEX * 4096) );
$this->getView()->assign( 'lep', $lep );
$this->getView()->assign( 'lncpu', $lncpu );
$this->getView()->assign( 'mep_cur', $MEP_INDEX );
$this->getView()->assign( 'lveinfo', $lveInfoDet );
$this->getView()->assign( 'period', $period );
}
}
?>