Guest User

Untitled

a guest
Apr 7th, 2012
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.03 KB | None | 0 0
  1. <?php
  2. /*  PHP System Status
  3.  *  ------------------------------------------
  4.  *  Author: wutno (#/g/tv - Rizon)
  5.  *  Last update: 1/4/2012 5:28AM -5GMT (USELESS BLOAT)
  6.  *
  7.  *
  8.  *  GNU License Agreement
  9.  *  ---------------------
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License version 2 as
  12.  *  published by the Free Software Foundation.
  13.  *
  14.  *  This program is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with this program; if not, write to the Free Software
  21.  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22.  *
  23.  *  http://www.gnu.org/licenses/gpl-2.0.txt
  24.  */
  25.  
  26. function kb2bytes($kb){
  27.     return round($kb * 1024, 2);
  28. }
  29. function format_bytes($bytes){
  30.     if ($bytes < 1024){ return $bytes; }
  31.     else if ($bytes < 1048576){ return round($bytes / 1024, 2).'KB'; }
  32.     else if ($bytes < 1073741824){ return round($bytes / 1048576, 2).'MB'; }
  33.     else if ($bytes < 1099511627776){ return round($bytes / 1073741824, 2).'GB'; }
  34.     else{ return round($bytes / 1099511627776, 2).'TB'; }
  35. }
  36. function numbers_only($string){
  37.     return preg_replace('/[^0-9]/', '', $string);
  38. }
  39. function calculate_percentage($used, $total){
  40.     return @round(100 - $used / $total * 100, 2);
  41. }
  42.  
  43. #users, uptime, load avgs
  44. $uptime = exec('uptime');
  45. preg_match('/ (.+) up (.+) user(.+): (.+)/', $uptime, $update_out);
  46. $users_out = substr($update_out[2], strrpos($update_out[2], ' ')+1);
  47. $uptime_out = substr($update_out[2], 0, strrpos($update_out[2], ' ')-2);
  48. $load_out = str_replace(', ',', <small>',$update_out[4]).str_repeat('</small>',2);
  49.  
  50. #HDD info
  51. $harddrive = explode(' ', preg_replace('/\s\s+/', ' ', exec('df /dev/xvda1')));
  52. $harddrive_out = format_bytes(kb2bytes($harddrive[2])).'<small> / '.format_bytes(kb2bytes($harddrive[1])).' <small>('.calculate_percentage(kb2bytes($harddrive[2]), kb2bytes($harddrive[1])).'% Free)</small></small>';
  53.  
  54. #bandwidth info
  55. $vnstat = explode(';', shell_exec('vnstat --oneline'));
  56. $vnstat[8] = '&#8595; '.$vnstat[8];
  57. $vnstat[9] = ' <small>&#8593; '.$vnstat[9];
  58. $vnstat[10] = ' <small>&#8597; '.$vnstat[10];
  59. $vnstat[11] = ' @ ~'.$vnstat[11];
  60.  
  61. #ram and swap
  62. $memory = array( 'Total RAM'  => 'MemTotal',
  63.                  'Free RAM'   => 'MemFree',
  64.                  'Cached RAM' => 'Cached',
  65.                  'Total Swap' => 'SwapTotal',
  66.                  'Free Swap'  => 'SwapFree' );
  67. foreach ($memory as $key => $value){
  68.     $memory[$key] = kb2bytes(numbers_only(exec('grep -E "^'.$value.'" /proc/meminfo')));
  69. }
  70. $memory['Used Swap'] = $memory['Total Swap'] - $memory['Free Swap'];
  71. $memory['Used RAM'] = $memory['Total RAM'] - $memory['Free RAM'] - $memory['Cached RAM'];
  72. $memory['RAM Percent Free'] = calculate_percentage($memory['Used RAM'],$memory['Total RAM']);
  73. $memory['Swap Percent Free'] = calculate_percentage($memory['Used Swap'],$memory['Total Swap']);
  74. $memory_out = format_bytes($memory['Used RAM']).'<small> / '.format_bytes($memory['Total RAM']).' <small> *'.format_bytes($memory['Cached RAM']).' Cached ('.$memory['RAM Percent Free'].'% Free)</small></small>';
  75. $swap_out = format_bytes($memory['Used Swap']).'<small> / '.format_bytes($memory['Total Swap']).' <small>('.$memory['Swap Percent Free'].'% Free)</small></small>';
  76. ?>
  77. <!DOCTYPE html>
  78. <html>
  79.     <head>
  80.         <title>Server status</title>
  81.         <meta name="robots" content="noindex, nofollow, noarchive, nosnippet, noodp" /> <!-- I fucking hate robots... -->
  82.         <meta name="description" content="Status page for #/g/tv shell server." />
  83.         <meta charset="UTF-8" />
  84.         <style type="text/css">
  85.             span { color: #fff;display: block;font-size: 1.3em;margin-bottom: .5em;padding: 0 .5em; }
  86.             html { background-color: #000;color: #777;font-family: sans-serif; font-size: 1.8em;padding: 1em 2em; }
  87.             div { float: right;text-align: right; }
  88.             a { color: #68c;display: block;font-size: 1.7em;text-decoration: none; }
  89.             small { color: #bbb; }
  90.             small>small { color: #777; }
  91.         </style>
  92.     </head>
  93.     <body>
  94.         server time<span><?=date("Y-F-j H:i:s", time());?></span> <!-- Server time is acutally PHP time since PHP wants to bitch -->
  95.         uptime<span><?=$uptime_out;?></span> <!-- Server uptime -->
  96.         users logged in<span><?=$users_out;?></span> <!-- Users logged in -->
  97.         load<span><?=$load_out;?></span> <!-- CPU load averages -->
  98.         memory<span><?=$memory_out;?></span> <!-- RAM usage -->
  99.         swap<span><?=$swap_out;?></span> <!-- SWAP usage -->
  100.         disk<span><?=$harddrive_out;?></span> <!-- Disk information -->
  101.         bandwidth used (m)<small></small><span><?=$vnstat[8].$vnstat[9].$vnstat[10].$vnstat[11];?></small></small></span> <!-- Monthly bandwidth usage -->
  102.     </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment