Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 19th, 2011  |  syntax: PHP  |  size: 2.72 KB  |  views: 49  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3. <title>PCH - Stats</title>
  4. </head>
  5. <body bgcolor="#dddddd">
  6. <h1>PCH - Stats</h1>
  7.  
  8. <h2>Load & Uptime</h2>
  9. <pre>
  10. <?php
  11. //GET SERVER LOADS
  12. $loadresult = @exec("uptime");
  13. preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
  14.  
  15. //GET SERVER UPTIME
  16. $uptime = explode(" up ", $loadresult);
  17. $uptime = explode(",", $uptime[1]);
  18. $uptime = $uptime[0].", ".$uptime[1];
  19.  
  20. // If uptime is <1day it will show a part of the load averages..
  21. // This is a dirty fix
  22. if  ((substr($uptime,2,1)==":") OR (substr($uptime,3,3)=="min")) {
  23. $uptime = substr($uptime,0,-21);
  24. }
  25.  
  26. echo "<b>Load Averages:</b>\t".$avgs[1] .", ". $avgs[2] .", ". $avgs[3] ."\n";
  27. echo "<b>Uptime:</b>\t\t".trim($uptime)."\n";
  28. ?>
  29. </pre>
  30.  
  31. <hr width="300px" align="left" />
  32.  
  33. <h2>Disk usage</h2>
  34. <pre>
  35. <?php
  36. $free = disk_free_space(".");
  37. $total = disk_total_space(".");
  38. $used = $total-$free;
  39.  
  40. function bytes2SI($bytes) {
  41.     $si_prefix = array( "B", "KiB", "MiB", "GiB", "TiB", "EiB", "ZiB", "YiB" );
  42.     $base = 1024;
  43.     $class = min((int)log($bytes , $base) , count($si_prefix) - 1);
  44.     return sprintf("%1.2f" , $bytes / pow($base,$class)) . " " . $si_prefix[$class];
  45. }
  46.  
  47. // Percentages
  48. // number_format() ipv round() om bij ronde getallen
  49. // bijkomende nullen achter de comma te zetten.
  50. $usedperc = number_format($used*100/$total, 1);
  51. $freeperc = number_format($free*100/$total, 1);
  52.  
  53. // Free & Total space
  54. echo "<b>Total space:</b>\t" . bytes2SI($total) . "\t100  %\n";
  55. echo "<b>Used space:</b>\t" . bytes2SI($used) . "\t".$usedperc . " %\n";
  56. echo "<b>Free space:</b>\t" . bytes2SI($free) . "\t".$freeperc . " %\n";
  57.  
  58. ?></pre>
  59.  
  60. <hr width="300px" align="left" />
  61.  
  62. <h2>Programs status</h2>
  63. <pre>
  64. <?php
  65.  
  66. function checkactive ($procesname) {
  67. exec("ps aux | grep -i $procesname", $output);
  68.  
  69. if(is_dir("/share/Apps/".$procesname)) {
  70.  
  71.         echo "\t<b>".$procesname."</b> is installed ";
  72.  
  73.         if (count($output) > 2) {       echo "and running.\n";}
  74.         else {                                          echo "but NOT running.\n";}
  75.        
  76. }else {
  77.         echo "\t<b>".$procesname."</b> is NOT installed\n";
  78. }
  79.  
  80. } // End of function checkactive
  81.  
  82.  
  83. // ATTENTION: When adding other apps..
  84. // use the foldername like in /share/Apps/
  85. // the php function is_dir() for foldername IS CaSE SEnsItiVE
  86. // the grep command uses the -i option to make it case-insentive
  87.  
  88.  
  89. echo "<b>CouchPotato:</b>";
  90. checkactive (couchpotato);
  91.  
  92. echo "<b>lighttpd:</b>";
  93. checkactive (lighttpd);
  94.  
  95. echo "<b>NZBget:</b>\t";
  96. checkactive (NZBget);
  97.  
  98. echo "<b>Sick Beard:</b>";
  99. checkactive (sickbeard);
  100.  
  101. echo "<b>Telnetd:</b>";
  102. checkactive (Telnetd);
  103.  
  104. echo "<b>Transmission:</b>";
  105. checkactive (Transmission);
  106. ?></pre>
  107.  
  108. <hr width="300px" align="left" />
  109.  
  110. Go back <a href="/">Home</a>
  111.  
  112. </body>
  113. </html>
  114.  
clone this paste RAW Paste Data