[7. June 2013] Youporn available now | [19. April 2013] A-400 Advanced Network Setup | [11 Jan. 2013] Customize your A-400 Home Screen

Firmware: A-400 [13 May 2013] | C-300 [30 Nov. 2012] | A-300 [30 Nov. 2012] | C-200 RC1 [13 June 2013] | A-200/A-210 RC1 [13 June 2013]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Post Reply 
PHP Page showing PCH Stats
11-18-2011, 08:57 PM (This post was last modified: 11-19-2011 05:12 PM by Slevin.)
Post: #1
PHP Page showing PCH Stats
I made a simple Stats page for my PCH in PHP.

The page has three parts:
  1. Load & Uptime
  2. Disk usage
  3. Programs status: Checks if installed and (if installed) if it's running

Here is an example running on my PCH:
http://slevo.no-ip.org:8080/pch_stats.php

And here is the source: http://pastebin.com/6mtQKq0A
PHP Code:
<html>
<
head>
<
title>PCH Stats</title>
</
head>
<
body bgcolor="#dddddd">
<
h1>PCH Stats</h1>

<
h2>Load Uptime</h2>
<
pre>
<?
php
//GET SERVER LOADS
$loadresult = @exec("uptime");
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);

//GET SERVER UPTIME
$uptime explode(" up "$loadresult);
$uptime explode(","$uptime[1]);
$uptime $uptime[0].", ".$uptime[1];

// If uptime is <1day it will show a part of the load averages..
// This is a dirty fix
if  ((substr($uptime,2,1)==":") OR (substr($uptime,3,3)=="min")) {
$uptime substr($uptime,0,-21);
}

echo 
"<b>Load Averages:</b>\t".$avgs[1] .", "$avgs[2] .", "$avgs[3] ."\n";
echo 
"<b>Uptime:</b>\t\t".trim($uptime)."\n";
?>
</pre>

<hr width="300px" align="left" />

<h2>Disk usage</h2>
<pre>
<?php
$free 
disk_free_space(".");
$total disk_total_space(".");
$used $total-$free;

function 
bytes2SI($bytes) {
    
$si_prefix = array( "B""KiB""MiB""GiB""TiB""EiB""ZiB""YiB" );
    
$base 1024;
    
$class min((int)log($bytes $base) , count($si_prefix) - 1);
    return 
sprintf("%1.2f" $bytes pow($base,$class)) . " " $si_prefix[$class];
}

// Percentages
// number_format() ipv round() om bij ronde getallen
// bijkomende nullen achter de comma te zetten.
$usedperc number_format($used*100/$total1);
$freeperc number_format($free*100/$total1);

// Free & Total space
echo "<b>Total space:</b>\t" bytes2SI($total) . "\t100  %\n";
echo 
"<b>Used space:</b>\t" bytes2SI($used) . "\t".$usedperc " %\n";
echo 
"<b>Free space:</b>\t" bytes2SI($free) . "\t".$freeperc " %\n";

?></pre>

<hr width="300px" align="left" />

<h2>Programs status</h2>
<pre>
<?php

function checkactive ($procesname) {
exec("ps aux | grep -i $procesname"$output);

if(
is_dir("/share/Apps/".$procesname)) {

    echo 
"\t<b>".$procesname."</b> is installed ";

    if (
count($output) > 2) {    echo "and running.\n";}
    else {                        echo 
"but NOT running.\n";}
    
}else {
    echo 
"\t<b>".$procesname."</b> is NOT installed\n";
}

// End of function checkactive


// ATTENTION: When adding other apps..
// use the foldername like in /share/Apps/
// the php function is_dir() for foldername IS CaSE SEnsItiVE
// the grep command uses the -i option to make it case-insentive


echo "<b>CouchPotato:</b>";
checkactive (couchpotato);

echo 
"<b>lighttpd:</b>";
checkactive (lighttpd);

echo 
"<b>NZBget:</b>\t";
checkactive (NZBget);

echo 
"<b>Sick Beard:</b>";
checkactive (sickbeard);

echo 
"<b>Telnetd:</b>";
checkactive (Telnetd);

echo 
"<b>Transmission:</b>";
checkactive (Transmission);
?></pre>

<hr width="300px" align="left" />

Go back <a href="/">Home</a>

</body>
</html> 

My PCH-A110 Stats | Samsung LE32A656 | Logitech Z-2300 | Harmony One
Oversight | Sick Beard DOGnzb | NZBGet | Transmission | Lighttpd | ...
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Did someone compile ath9k_htc module for pch-a110? kay 1 1,180 04-17-2013 02:27 AM
Last Post: dony71
  Faster PHP server CSI package journey4712 174 63,981 03-30-2013 01:12 PM
Last Post: o34171@rtrtr.com
Star [Apps] Bierdopje 4 NMT PHP script SilverViper 4 1,419 11-26-2012 04:57 PM
Last Post: Djiest
  PCH Audio playlist format? Nono 4 1,806 10-05-2011 10:10 PM
Last Post: Nono
Brick Building Freenas box to work with PCH and My Lil Movie Jukebox Casuall 10 5,462 07-17-2011 04:23 AM
Last Post: Casuall
  how to start mono from php harrykausl 5 2,360 07-10-2011 10:01 PM
Last Post: harrykausl
  PCH A-110 and LG LW6500 SMART TV tommbslk 1 2,207 06-25-2011 05:13 PM
Last Post: Warden
  Windows 7 NFS client to pch A110 - Working!! johnpoz 5 4,583 02-26-2011 06:59 AM
Last Post: zytham
  Streaming from PCH to network naight 9 3,491 02-11-2011 05:26 PM
Last Post: naight
  Looking for the binary file of Fuppes for pch-110 gcf 0 1,562 01-29-2011 12:57 PM
Last Post: gcf

Forum Jump: