Skip to content

Instantly share code, notes, and snippets.

@joshhartman
Last active January 7, 2022 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshhartman/18d72f5901ed6e374c5508bf8bdb79b9 to your computer and use it in GitHub Desktop.
Save joshhartman/18d72f5901ed6e374c5508bf8bdb79b9 to your computer and use it in GitHub Desktop.
cPanel Linux Server System Info Summary
<?php
function sys_uptime(){
$uptime = '';
if(is_readable('/proc/uptime')){
$str = @file_get_contents('/proc/uptime');
$num = floatval($str);
$secs = $num % 60;
$num = (int)($num / 60);
$mins = $num % 60;
$num = (int)($num / 60);
$hours = $num % 24;
$num = (int)($num / 24);
$days = $num;
$uptime = $days.' days, '.$hours.' hours, '.$mins.' minutes, '.$secs.' seconds';
} // /is_readable('/proc/uptime')
return $uptime;
}
$num_cpus=trim(`less /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l`);
$cpu_info=trim(`less /proc/cpuinfo`);
$num_threads=trim(`nproc`);
$mem_info=`free -h`;
$disk_info=`df -h`;
preg_match_all('/^cpu cores.*?(\d)/m', $cpu_info, $matches);
$num_cores = array_sum($matches[1]);
$load=sys_getloadavg();
$cpanel_info=json_decode(`uapi ServerInformation get_information --output=json`)->result->data;
$cpanel_info_display='';
foreach($cpanel_info as $k=>$obj){
if($obj->type=='service'){
unset($cpanel_info[$k]);
}else{
$cpanel_info_display.="{$obj->name}: {$obj->value}".PHP_EOL.PHP_EOL;
}
}
echo '<pre>';
echo "Hostname: ".trim(`hostname`).PHP_EOL.PHP_EOL;
echo trim(`less /proc/version`).PHP_EOL.PHP_EOL;
echo "Uptime: ".sys_uptime().PHP_EOL.PHP_EOL;
echo "Load Averages: {$load[0]} {$load[1]} {$load[2]}".PHP_EOL.PHP_EOL;
echo "Number of CPUs: ".$num_cpus.PHP_EOL.PHP_EOL;
echo "Total Number of CPU Cores: ".$num_cores.PHP_EOL.PHP_EOL;
echo "Total Number of CPU Threads: ".$num_threads.PHP_EOL.PHP_EOL;
echo $mem_info.PHP_EOL.PHP_EOL;
echo $cpanel_info_display;
echo '<textarea style="width:700px; height:500px; max-width:100%;">'.$cpu_info.'</textarea>'.PHP_EOL.PHP_EOL;
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment