Guest User

Raspberry Pi System Info

a guest
Dec 30th, 2012
315
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     header("Cache-Control: no-cache, must-revalidate");
  3.     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  4.     header("Pragma: no-cache");
  5.  
  6.     function NumberWithCommas($in)
  7.     {
  8.         return number_format($in);
  9.     }
  10.     function  WriteToStdOut($text)
  11.     {
  12.         $stdout = fopen('php://stdout','w') or die($php_errormsg);
  13.         fputs($stdout, "\n" . $text);
  14.     }
  15.    
  16.     $current_time = date('d M Y') . '<br />' . date('h:i:s T');
  17.     $frequency = NumberWithCommas(file_get_contents("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq") / 1000);
  18.     $processor = str_replace("-compatible processor", "", explode(": ", chop(file("/proc/cpuinfo")[0]))[1]);
  19.     $cpu_temperature = round(file_get_contents("/sys/class/thermal/thermal_zone0/temp") / 1000, 1);
  20.     //$RX = exec("ifconfig eth0 | grep 'RX bytes'| cut -d: -f2 | cut -d' ' -f1");
  21.     //$TX = exec("ifconfig eth0 | grep 'TX bytes'| cut -d: -f3 | cut -d' ' -f1");
  22.     $system = chop(file_get_contents("/proc/sys/kernel/ostype"));
  23.     $host = chop(file_get_contents("/proc/sys/kernel/hostname"));
  24.     $kernel = chop(file_get_contents("/proc/sys/kernel/osrelease"));
  25.    
  26.     //Uptime
  27.     $uptime_array = explode(" ", file_get_contents("/proc/uptime"));
  28.     $seconds = round($uptime_array[0], 0);
  29.     $minutes = $seconds / 60;
  30.     $hours = $minutes / 60;
  31.     $days = floor($hours / 24);
  32.     $hours = sprintf('%02d', floor($hours - ($days * 24)));
  33.     $minutes = sprintf('%02d', floor($minutes - ($days * 24 * 60) - ($hours * 60)));
  34.     if ($days == 0):
  35.         $uptime = $hours . ":" .  $minutes . " (hh:mm)";
  36.     elseif($days == 1):
  37.         $uptime = $days . " day, " .  $hours . ":" .  $minutes . " (hh:mm)";
  38.     else:
  39.         $uptime = $days . " days, " .  $hours . ":" .  $minutes . " (hh:mm)";
  40.     endif;
  41.    
  42.     //CPU Usage
  43.     $output1 = null;
  44.     $output2 = null;
  45.     //First sample
  46.     $output1 = file("/proc/stat");
  47.     //Sleep before second sample
  48.     sleep(1);
  49.     //Second sample
  50.     $output2 = file("/proc/stat");
  51.     $cpuload = 0;
  52.     for ($i=0; $i < 1; $i++)
  53.     {
  54.         //First row
  55.         $cpu_stat_1 = explode(" ", $output1[$i+1]);
  56.         $cpu_stat_2 = explode(" ", $output2[$i+1]);
  57.         //Init arrays
  58.         $info1 = array("user"=>$cpu_stat_1[1], "nice"=>$cpu_stat_1[2], "system"=>$cpu_stat_1[3], "idle"=>$cpu_stat_1[4]);
  59.         $info2 = array("user"=>$cpu_stat_2[1], "nice"=>$cpu_stat_2[2], "system"=>$cpu_stat_2[3], "idle"=>$cpu_stat_2[4]);
  60.         $idlesum = $info2["idle"] - $info1["idle"] + $info2["system"] - $info1["system"];
  61.         $sum1 = array_sum($info1);
  62.         $sum2 = array_sum($info2);
  63.         //Calculate the cpu usage as a percent
  64.         $load = (1 - ($idlesum / ($sum2 - $sum1))) * 100;
  65.         $cpuload += $load;
  66.     }
  67.     $cpuload = round($cpuload, 1); //One decimal place
  68.    
  69.     //Memory Utilisation
  70.     $meminfo = file("/proc/meminfo");
  71.     for ($i = 0; $i < count($meminfo); $i++)
  72.     {
  73.         list($item, $data) = split(":", $meminfo[$i], 2);
  74.         $item = trim(chop($item));
  75.         $data = intval(preg_replace("/[^0-9]/", "", trim(chop($data)))); //Remove non numeric characters
  76.         switch($item)
  77.         {
  78.             case "MemTotal": $total_mem = $data; break;
  79.             case "MemFree": $free_mem = $data; break;
  80.             case "SwapTotal": $total_swap = $data; break;
  81.             case "SwapFree": $free_swap = $data; break;
  82.             case "Buffers": $buffer_mem = $data; break;
  83.             case "Cached": $cache_mem = $data; break;
  84.             default: break;
  85.         }
  86.     }
  87.     $used_mem = $total_mem - $free_mem;
  88.     $used_swap = $total_swap - $free_swap;
  89.     $percent_free = round(($free_mem / $total_mem) * 100);
  90.     $percent_used = round(($used_mem / $total_mem) * 100);
  91.     $percent_swap = round((($total_swap - $free_swap ) / $total_swap) * 100);
  92.     $percent_swap_free = round(($free_swap / $total_swap) * 100);
  93.     $percent_buff = round(($buffer_mem / $total_mem) * 100);
  94.     $percent_cach = round(($cache_mem / $total_mem) * 100);
  95.     $used_mem = NumberWithCommas($used_mem);
  96.     $used_swap = NumberWithCommas($used_swap);
  97.     $total_mem = NumberWithCommas($total_mem);
  98.     $free_mem = NumberWithCommas($free_mem);
  99.     $total_swap = NumberWithCommas($total_swap);
  100.     $free_swap = NumberWithCommas($free_swap);
  101.     $buffer_mem = NumberWithCommas($buffer_mem);
  102.     $cache_mem = NumberWithCommas($cache_mem);
  103.  
  104.     //Disk space check
  105.     $lines = file("/proc/mounts");
  106.  
  107.     foreach($lines as $line) {
  108.         if (preg_match('/tmpfs|devtmpfs|devpts|rootfs|proc|sysfs/', $line) == false) {
  109.             list($drive[], $mount[], $typex[]) = explode(" ", $line);
  110.         }
  111.     }
  112.  
  113.     foreach($mount as $dir) {
  114.         $avail[] = disk_free_space($dir) / 1048576;
  115.         $size[] = disk_total_space($dir) / 1048576;
  116.         $used[] = (disk_total_space($dir) - disk_free_space($dir)) / 1048576;
  117.         $percent[] = round((1 - (disk_free_space($dir) / disk_total_space($dir)))*100);
  118.     }
  119. ?>
  120. <!DOCTYPE html>
  121. <html lang="en">
  122.     <head>
  123.         <title>SysInfo: <?php echo $host; ?></title>
  124.         <meta http-equiv="refresh" content="60" />
  125.         <style type="text/css">
  126.             a
  127.             {
  128.                 color:white;
  129.                 padding-top:5px;
  130.                 display:block;
  131.             }
  132.             a:hover
  133.             {
  134.                 text-decoration:none;
  135.             }
  136.             td
  137.             {
  138.                 font-family:"DejaVu Sans",Arial,Helvetica,sans-serif;
  139.                 font-size:12px;
  140.                 vertical-align:top;
  141.                 padding-left:2px;
  142.                 padding-right:2px;
  143.                 background:#1c1c1c;
  144.             }
  145.             td.center
  146.             {
  147.                 text-align:center;
  148.             }
  149.             td.head
  150.             {
  151.                 font-weight:bold;
  152.                 padding-top:3px;
  153.                 padding-bottom:3px;
  154.             }
  155.             td.right
  156.             {
  157.                 text-align:right;
  158.                 padding-right:6px;
  159.             }
  160.             table
  161.             {
  162.                 width: 320px; border-spacing:0;
  163.                 border-collapse:collapse;
  164.             }
  165.             html,body,.darkbackground
  166.             {
  167.                 background:#0C0C0C;
  168.             }
  169.             body
  170.             {
  171.                 color:#E6E6E6;
  172.             }
  173.             td.column1
  174.             {
  175.                 width:60px;
  176.             }
  177.             td.column3
  178.             {
  179.                 width:120px;
  180.             }
  181.             td.column4
  182.             {
  183.                 width:30px;
  184.             }
  185.             div#bar1, div#bar2, div#bar3, div#bar4, div#bar5, div#bar6
  186.             {
  187.                 height:12px;
  188.                 width:0px;
  189.                 transition:width 2s;
  190.                 <?php
  191.                     $agent = "";
  192.                     if(isset($_SERVER['HTTP_USER_AGENT']))
  193.                     {
  194.                         $agent = $_SERVER['HTTP_USER_AGENT'];
  195.                     }
  196.                     if(strlen(stristr($agent,"applewebkit")) > 0 ) echo "\n\t\t\t\t-webkit-transition:width 2s;\n";
  197.                     else if(strlen(stristr($agent,"gecko")) > 0 ) echo "\n\t\t\t\t-moz-transition:width 2s;\n";
  198.                     else if(strlen(stristr($agent,"opera")) > 0 ) echo "\n\t\t\t\t-o-transition:width 2s;\n";
  199.                 ?>
  200.             }
  201.             div#bar1 { background-color:#D78787; }
  202.             div#bar2 { background-color:#AFD787; }
  203.             div#bar3 { background-color:#F7F7AF; }
  204.             div#bar4 { background-color:#87AFD7; }
  205.             div#bar5 { background-color:#D7AFD7; }
  206.             div#bar6 { background-color:#AFD7D7; }
  207.         </style>
  208.         <script type="text/javascript">
  209.             function updateText(objectId, text)
  210.             {
  211.                 document.getElementById(objectId).textContent = text;
  212.             }
  213.             function updateHTML(objectId, html)
  214.             {
  215.                 document.getElementById(objectId).innerHTML = html;
  216.             }
  217.             function updateDisplay()
  218.             {
  219. <?php
  220.                 echo "\n\t\t\t\tupdateText(\"host\",\"$host\");";
  221.                 echo "\n\t\t\t\tupdateHTML(\"time\",\"$current_time\");";
  222.                 echo "\n\t\t\t\tupdateText(\"kernel\",\"$system\" + \" \" + \"$kernel\");";
  223.                 echo "\n\t\t\t\tupdateText(\"processor\",\"$processor\");";
  224.                 echo "\n\t\t\t\tupdateText(\"freq\",\"$frequency\" + \"MHz\");";
  225.                 echo "\n\t\t\t\tupdateText(\"cpuload\",\"$cpuload%\");";
  226.                 echo "\n\t\t\t\tupdateText(\"cpu_temperature\",\"$cpu_temperature\" + \"°C\");";
  227.                 echo "\n\t\t\t\tupdateText(\"uptime\",\"$uptime\");";
  228.  
  229.                 echo "\n\t\t\t\tupdateText(\"total_mem\",\"$total_mem\" + \" kB\");";
  230.                 echo "\n\t\t\t\tupdateText(\"used_mem\",\"$used_mem\" + \" kB\");";
  231.                 echo "\n\t\t\t\tupdateText(\"percent_used\",\"$percent_used%\");";
  232.                 echo "\n\t\t\t\tupdateText(\"free_mem\",\"$free_mem\" + \" kB\");";
  233.                 echo "\n\t\t\t\tupdateText(\"percent_free\",\"$percent_free%\");";
  234.                 echo "\n\t\t\t\tupdateText(\"buffer_mem\",\"$buffer_mem\" + \" kB\");";
  235.                 echo "\n\t\t\t\tupdateText(\"percent_buff\",\"$percent_buff%\");";
  236.                 echo "\n\t\t\t\tupdateText(\"cache_mem\",\"$cache_mem\" + \" kB\");";
  237.                 echo "\n\t\t\t\tupdateText(\"percent_cach\",\"$percent_cach%\");";
  238.  
  239.                 echo "\n\t\t\t\tupdateText(\"total_swap\",\"$total_swap\" + \" kB\");";
  240.                 echo "\n\t\t\t\tupdateText(\"used_swap\",\"$used_swap\" + \" kB\");";
  241.                 echo "\n\t\t\t\tupdateText(\"percent_swap\",\"$percent_swap%\");";
  242.                 echo "\n\t\t\t\tupdateText(\"free_swap\",\"$free_swap\" + \" kB\");";
  243.                 echo "\n\t\t\t\tupdateText(\"percent_swap_free\",\"$percent_swap_free%\");\n";
  244. ?>
  245.                 document.getElementById("bar1").style.width = "<?php echo $percent_used; ?>px";
  246.                 document.getElementById("bar2").style.width = "<?php echo $percent_free; ?>px";
  247.                 document.getElementById("bar3").style.width = "<?php echo $percent_buff; ?>px";
  248.                 document.getElementById("bar4").style.width = "<?php echo $percent_cach; ?>px";
  249.                 document.getElementById("bar5").style.width = "<?php echo $percent_swap; ?>px";
  250.                 document.getElementById("bar6").style.width = "<?php echo $percent_swap_free; ?>px";
  251.             }
  252.         </script>
  253.     </head>
  254.     <body onload="updateDisplay()">
  255. <!--    <h3>mikrocontroller.net Stresstest</h3> -->
  256.         <table>
  257.             <tr>
  258.                 <td colspan="4" class="head center">General Info</td>
  259.             </tr>
  260.             <tr>
  261.                 <td colspan="2">Hostname</td>
  262.                 <td colspan="2" id="host"></td>
  263.             </tr>
  264.             <tr>
  265.                 <td colspan="2">System Time</td>
  266.                 <td colspan="2" id="time"></td>
  267.             </tr>
  268.             <tr>
  269.                 <td colspan="2">Kernel</td>
  270.                 <td colspan="2" id="kernel"></td>
  271.             </tr>
  272.             <tr>
  273.                 <td colspan="2">Processor</td>
  274.                 <td colspan="2" id="processor"></td>
  275.             </tr>
  276.             <tr>
  277.                 <td colspan="2">CPU Frequency</td>
  278.                 <td colspan="2" id="freq"></td>
  279.             </tr>
  280.             <tr>
  281.                 <td colspan="2">CPU Load</td>
  282.                 <td colspan="2" id="cpuload"></td>
  283.             </tr>
  284.             <tr>
  285.                 <td colspan="2">CPU Temperature</td>
  286.                 <td colspan="2" id="cpu_temperature"></td>
  287.             </tr>
  288.             <tr>
  289.                 <td colspan="2">Uptime</td>
  290.                 <td colspan="2" id="uptime"></td>
  291.             </tr>
  292.             <tr>
  293.                 <td colspan="4" class="darkbackground">&nbsp;</td>
  294.             </tr>
  295.             <tr>
  296.                 <td colspan="2" class="head right">Memory:</td>
  297.                 <td colspan="2" class="head" id="total_mem"></td>
  298.             </tr>
  299.             <tr>
  300.                 <td class="column1">Used</td>
  301.                 <td class="right" id="used_mem"></td>
  302.                 <td class="column3"><div id="bar1">&nbsp;</div></td>
  303.                 <td class="right column4" id="percent_used"></td>
  304.             </tr>
  305.             <tr>
  306.                 <td>Free</td>
  307.                 <td class="right" id="free_mem"></td>
  308.                 <td><div id="bar2"></div></td>
  309.                 <td class="right" id="percent_free"></td>
  310.             </tr>
  311.             <tr>
  312.                 <td>Buffered</td>
  313.                 <td class="right" id="buffer_mem"></td>
  314.                 <td><div id="bar3"></div></td>
  315.                 <td class="right" id="percent_buff"></td>
  316.             </tr>
  317.             <tr>
  318.                 <td>Cached</td>
  319.                 <td class="right" id="cache_mem"></td>
  320.                 <td><div id="bar4"></div></td>
  321.                 <td class="right" id="percent_cach"></td>
  322.             </tr>
  323.             <tr>
  324.                 <td colspan="4" class="darkbackground">&nbsp;</td>
  325.             </tr>
  326.             <tr>
  327.                 <td colspan="2" class="head right">Swap:</td>
  328.                 <td colspan="2" class="head" id="total_swap"></td>
  329.             </tr>
  330.             <tr>
  331.                 <td>Used</td>
  332.                 <td class="right" id="used_swap"></td>
  333.                 <td><div id="bar5"></div></td>
  334.                 <td class="right" id="percent_swap"></td>
  335.             </tr>
  336.             <tr>
  337.                 <td>Free</td>
  338.                 <td class="right" id="free_swap"></td>
  339.                 <td><div id="bar6"></div></td>
  340.                 <td class="right" id="percent_swap_free"></td>
  341.             </tr>
  342.             <tr>
  343.                 <td colspan="4" class="darkbackground">&nbsp;</td>
  344.             </tr>
  345.         </table>
  346.         <table id="tblDiskSpace">
  347.             <tr>
  348.                 <td colspan="4" class="head center">Disk Usage</td>
  349.             </tr>
  350. <?php
  351.     for ($i = 0; $i < count($drive); $i++)
  352.     {
  353.         $total = number_format(round($size[$i])) . " MB";
  354.         $usedspace = number_format(round($used[$i])) . " MB";
  355.         $freespace = number_format(round($avail[$i])) . " MB";
  356.         echo "\n\t\t\t<tr>";
  357.         echo "\n\t\t\t\t<td class=\"head\" colspan=\"4\">" . $mount[$i] . " (" . $typex[$i] . ")</td>";
  358.         echo "\n\t\t\t</tr>";
  359.         echo "\n\t\t\t<tr>";
  360.         echo "\n\t\t\t\t<td>&nbsp;</td>";
  361.         echo "\n\t\t\t\t<td>Total Size</td>";
  362.         echo "\n\t\t\t\t<td class=\"right\">" . $total . "</td>";
  363.         echo "\n\t\t\t\t<td class=\"right\">&nbsp;</td>";
  364.         echo "\n\t\t\t</tr>";
  365.         echo "\n\t\t\t<tr>";
  366.         echo "\n\t\t\t\t<td>&nbsp;</td>";
  367.         echo "\n\t\t\t\t<td>Used</td>";
  368.         echo "\n\t\t\t\t<td class=\"right\">" . $usedspace . "</td>";
  369.         echo "\n\t\t\t\t<td class=\"right\">" . $percent[$i] . "%</td>";
  370.         echo "\n\t\t\t</tr>";
  371.         echo "\n\t\t\t<tr>";
  372.         echo "\n\t\t\t\t<td>&nbsp;</td>";
  373.         echo "\n\t\t\t\t<td>Available</td>";
  374.         echo "\n\t\t\t\t<td class=\"right\">" . $freespace . "</td>";
  375.         echo "\n\t\t\t\t<td class=\"right\">" . (100-(floatval($percent[$i]))) . "%</td>";
  376.         echo "\n\t\t\t</tr>";
  377.         if ($i < $count-1):
  378.             echo "\n\t\t\t<tr><td colspan=\"4\">&nbsp;</td></tr>";
  379.         endif;
  380.     }
  381. ?>
  382.         </table>
  383.         <table>
  384.             <tr>
  385.                 <td class="right darkbackground"><a href="javascript:location.reload(true);" title="Refresh">Refresh</a></td>
  386.             </tr>
  387.         </table>
  388.     </body>
  389. </html>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×