CPU/Sys-Infos

  • Ich hab ein kleines php Script geschrieben um aktuelle Informationen (es wird der aktuelle, minimal und maximal Wert der CPU und GPU Temperatur sowie CPU Taktung im Browsercache gespeichert) im Webbrowser anzuzeigen. Das Script wird bei geöffnetem Browser alle 10 Sekunden neu ausgeführt..

    Permanent angezeigt wird derzeit:

    - CPU Temperatur & Frequence
    - Kernel Informationen
    - Uptime
    - Memory Usage (free -m)
    - CPU Auslastung (User, Nice, System, Idle, Load und ein average CPU load als Balken)


    Optional, über den Befehl vcgencmd, angezeigt wird:

    - GPU Temperatur
    - config.txt Werte (sowohl default als auch custom)
    - Frequences
    - Codecs
    - Volts
    - Memory-Split
    ...also eigentlich alles was über den Befehl vcgencmd möglich ist...


    Wie im ersten Satz bereits erwähnt, werden CPU Temperatur, CPU Frequence sowie optional auch die GPU Temperatur für die Session gespeichert, also solange der Browser geöffnet ist, wird die Seite alle 10 Sekunden neu geladen und Current, Max und Min angezeigt - Steigt also zB die CPU Temperatur auf 60° weil er kurz mal ausgelastet wird, steht bei " Max " 60°C aber unter Current eben der aktuelle Wert von zB 58°C

    Es gibt auch 3 Buttons:

    RESET -> Zum zurücksetzen der Current / Max / Min Werte
    Use vcgencmd -> Zum benutzen des vcgencmd's (verursacht mehr CPU Load)
    Dont use vcgencmd -> Wie der Name schon sagt, zum nicht benutzen des vcgencmd's, wodurch das Script auch wesendlich(!!) weniger Load verursacht


    Problem:

    Nun tu ich mich allerdings ein bischen schwer was den HTML Part betrifft - irgendwie krieg ichs nicht gebacken die restlichen Tabellen vom vcgencmd vernünftig darstellen zu lassen :(
    Hab es auch schon mit div's probiert aber das hat es nur verschlimmert =(

    Allgemein Design is nich so mein Ding :lol:


    Kann mir da bitte jemand weiter helfen :huh: :helpnew:

    Hier ein Screenshot anhand dessen ersichtlich wird welches Problem ich habe:

    Spoiler anzeigen

    8l817zgtyb7m.png
    (die baule Linie rechts ist ein div für das ich nur vorrübergehend "border:1px" gesetzt hab und markiert mein Problem)


    Script:

    http://msi.to/file/30439

    Spoiler anzeigen

    [code=php]<?php
    /*
    v0.4

    /opt/vc/bin/vcgencmd support to get detailed Infos. Warning: makes much more CPU load!

    required /etc/sudoers entry to display GPU Temp , CPU Voltage and all other vcgencmd-values:
    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd
    */

    // CONFIG - START

    # Use RaspberryPI's /opt/vc/bin/vcgencmd ? [ 0 = no , 1 = yes ]
    $USEvcgencmd = 0;

    // CONFIG - END

    session_start();
    session_cache_expire(1440);
    $DURATION_start=microtime(true);
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title><?php echo $_SERVER['SERVER_NAME']; ?> - Informations</title>
    <meta HTTP-EQUIV=Refresh CONTENT='10'>
    <style type=text/css>

    div { border:1px solid #ccf; }

    body { font-size: 8pt; color: black; font-family: Verdana,arial,helvetica,serif; margin: 0 0 0 0; }
    .style1 {
    color: #999999;
    font-weight: bold;
    }
    div.progressbar {
    border: 1px solid gray;
    border-style: dotted;
    width: 40%;
    padding: 1px;
    background-color: #E0E0E0;
    margin: 0px;
    }
    div.progressbar div {
    height: 7px;
    background-color: #ff0000;
    width: 0%;
    }
    #vcgencmd {
    position:absolute;
    top:0px;
    left:700px;
    letter-spacing:0px;
    font-family:verdana, arial, helvetica, verdana, tahoma, sans-serif;
    }
    </style>
    </head>
    <body>

    <?php
    $buttonUSEvcgencmd = isset($_POST["USEvcgencmd"]) ? $_POST["USEvcgencmd"] : "";
    if (!isset($vcgencmd)) { $vcgencmd=0; }

    if (!empty($buttonUSEvcgencmd)) {
    if ($buttonUSEvcgencmd == "true") { $_SESSION['vcgencmd'] = 1; }
    if ($buttonUSEvcgencmd == "false") { $_SESSION['vcgencmd'] = 0; }
    }

    if (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 1) {
    $USEvcgencmd = 1;
    } elseif (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 0) {
    $USEvcgencmd = 0;
    }

    $RESET = isset($_POST["RESET"]) ? $_POST["RESET"] : "";
    if (!empty($RESET)) {
    if (isset($_SESSION['max_cputemp'])) { unset($_SESSION['max_cputemp']); }
    if (isset($_SESSION['min_cputemp'])) { unset($_SESSION['min_cputemp']); }
    if (isset($_SESSION['max_cpufreq'])) { unset($_SESSION['max_cpufreq']); }
    if (isset($_SESSION['min_cpufreq'])) { unset($_SESSION['min_cpufreq']); }
    if (isset($_SESSION['max_gputemp'])) { unset($_SESSION['max_gputemp']); }
    if (isset($_SESSION['min_gputemp'])) { unset($_SESSION['min_gputemp']); }
    }

    exec("cat /sys/class/thermal/thermal_zone0/temp",$cputemp);
    exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",$cpufreq);
    $cputemp = $cputemp[0] / 1000;
    $cpufreq = $cpufreq[0] / 1000;

    if ($USEvcgencmd == 1) {
    @exec("sudo /opt/vc/bin/vcgencmd measure_temp | sed -e \"s/temp=//\" -e \"s/'C//g\"",$gputemp);
    if (!empty($gputemp[0]) AND !preg_match("/VCHI initialization failed/",$gputemp[0])) { $vcgencmd = 1; }
    # vcgencmd command informations: http://elinux.org/RPI_vcgencmd_usage

    $CMD = 'sudo /opt/vc/bin/vcgencmd';

    if ($vcgencmd == 1) {
    # current active volts
    $VoltTypes = "core sdram_c sdram_i sdram_p";
    $volt_list = array();
    foreach (explode(" ",$VoltTypes) AS $vt) {
    $volt_list["$vt"] = exec("".$CMD." measure_volts ".$vt." | sed -e \"s/volt=//\"");
    }

    # current active settings
    exec("".$CMD." get_config int",$config_integers);
    $config_integer = array();
    foreach ($config_integers AS $integer) {
    preg_match('°(.*)=(.*)°',$integer,$int);
    if (isset($int[1]) AND !empty($int[1])) { $config_integer["$int[1]"] = $int[2]; }
    }

    # current active frequency's
    $ClockTypes = "arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi";
    $clock_list = array();
    foreach (explode(" ",$ClockTypes) AS $ct) {
    $clock_list["$ct"] = exec("".$CMD." measure_clock ".$ct." | cut -d'=' -f2");
    }

    # current codec enabled
    $CodecTypes = "H264 MPG2 WVC1 MPG4 MJPG WMV9";
    $codec_list = array();
    foreach (explode(" ",$CodecTypes) AS $ct) {
    $codec_list["$ct"] = exec("".$CMD." codec_enabled ".$ct." | cut -d'=' -f2");
    }

    # current mem split
    $MemTypes = "arm gpu";
    $mem_list = array();
    foreach (explode(" ",$MemTypes) AS $mt) {
    $mem_list["$mt"] = exec("".$CMD." get_mem ".$mt." | cut -d'=' -f2");
    }
    }
    }

    // max cpu
    if (!isset($_SESSION['max_cputemp'])) {
    $_SESSION['max_cputemp'] = $cputemp;
    } elseif ($_SESSION['max_cputemp'] < $cputemp) {
    $_SESSION['max_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['max_cpufreq'])) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    } elseif ($_SESSION['max_cpufreq'] < $cpufreq) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    }
    // min cpu
    if (!isset($_SESSION['min_cputemp'])) {
    $_SESSION['min_cputemp'] = $cputemp;
    } elseif ($cputemp < $_SESSION['min_cputemp']) {
    $_SESSION['min_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['min_cpufreq'])) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    } elseif ($cpufreq < $_SESSION['min_cpufreq']) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    }

    if (isset($vcgencmd) AND $vcgencmd == 1) {
    // max gpu
    if (!isset($_SESSION['max_gputemp'])) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    } elseif ($_SESSION['max_gputemp'] < $gputemp[0]) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    }
    // min gpu
    if (!isset($_SESSION['min_gputemp'])) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    } elseif ($gputemp[0] < $_SESSION['min_gputemp']) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    }
    }

    ?>

    <blockquote>
    <pre>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="left" valign="top">
    <form name='reset' action='' method='POST'>
    <button type='submit' value='true' name='RESET'>Reset</button>
    </form>
    </td>
    <td align="right" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='true' name='USEvcgencmd' class='USEvcgencmd'>Use vcgencmd</button>
    </form>
    </td>
    <td align="left" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='false' name='USEvcgencmd' class='USEvcgencmd'>Dont use vcgencmd</button>
    </form>
    </td>
    </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0">
    <tr>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cputemp; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_cputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_cputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Frequence</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cpufreq; ?> MHz</td>
    <td><?php echo $_SESSION['max_cpufreq']; ?> MHz</td>
    <td><?php echo $_SESSION['min_cpufreq']; ?> MHz</td>
    </tr>
    </table>
    </td>
    <?php
    if ($vcgencmd == 1) {
    ?>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>GPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $gputemp[0]; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_gputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_gputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>

    <?php
    if ($vcgencmd == 1) {
    // arrays: $config_integer $volt_list $clock_list $codec_list $mem_list
    echo "<div id='vcgencmd'>\n";
    echo " <table border='0' cellpadding='2' cellspacing='0'>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>config.txt integers:</b></td></tr>\n";
    foreach ($config_integer AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Frequences:</b></td></tr>\n";
    foreach ($clock_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Codecs:</b></td></tr>\n";
    foreach ($codec_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Volts:</b></td></tr>\n";
    foreach ($volt_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'> <b>Mem-Split:</b> </td></tr>\n";
    foreach ($mem_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " </table>\n";
    echo "</div>\n";
    }
    ?>

    <span class="style1">Kernel Information:</span>
    <?php echo php_uname(); ?><br/>

    <span class="style1">Uptime:</span>
    <?php system("uptime"); ?>

    <span class="style1">Memory Usage (MB):</span>
    <?php system("free -m"); ?>

    </pre>
    <p>
    <?php
    echo "<span class='style1'>CPU Load:</span><br/>\n";
    // Change this next line to specify an alternate temporary directory. Your
    // webserver MUST have write access to this directory if you plan to call
    // the CPULoad::get_load() method.
    define("TEMP_PATH","/tmp/");

    class CPULoad {
    function check_load() {
    $fd = fopen("/proc/stat","r");
    if ($fd) {
    $statinfo = explode("\n",fgets($fd, 1024));
    fclose($fd);
    foreach($statinfo as $line) {
    $info = explode(" ",$line);
    //echo "<pre>"; var_dump($info); echo "</pre>";
    if($info[0]=="cpu") {
    array_shift($info); // pop off "cpu"
    if(!$info[0]) array_shift($info); // pop off blank space (if any)
    $this->user = $info[0];
    $this->nice = $info[1];
    $this->system = $info[2];
    $this->idle = $info[3];
    // $this->print_current();
    return;
    }
    }
    }
    }
    function store_load() {
    $this->last_user = $this->user;
    $this->last_nice = $this->nice;
    $this->last_system = $this->system;
    $this->last_idle = $this->idle;
    }
    function save_load() {
    $this->store_load();
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","w");
    if ($fp) {
    fwrite($fp,time()."\n");
    fwrite($fp,$this->last_user." ".$this->last_nice." ".$this->last_system." ".$this->last_idle."\n");
    fwrite($fp,$this->load["user"]." ".$this->load["nice"]." ".$this->load["system"]." ".$this->load["idle"]." ".$this->load["cpu"]."\n");
    fclose($fp);
    }
    }
    function load_load() {
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","r");
    if ($fp) {
    $lines = explode("\n",fread($fp,1024));
    $this->lasttime = $lines[0];
    list($this->last_user,$this->last_nice,$this->last_system,$this->last_idle) = explode(" ",$lines[1]);
    list($this->load["user"],$this->load["nice"],$this->load["system"],$this->load["idle"],$this->load["cpu"]) = explode(" ",$lines[2]);
    fclose($fp);
    } else {
    $this->lasttime = time() - 60;
    $this->last_user = $this->last_nice = $this->last_system = $this->last_idle = 0;
    $this->user = $this->nice = $this->system = $this->idle = 0;
    }
    }
    function calculate_load() {
    //$this->print_current();
    $d_user = $this->user - $this->last_user;
    $d_nice = $this->nice - $this->last_nice;
    $d_system = $this->system - $this->last_system;
    $d_idle = $this->idle - $this->last_idle;
    //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br/>",$d_user,$d_nice,$d_system,$d_idle);
    $total=$d_user+$d_nice+$d_system+$d_idle;
    if ($total<1) $total=1;
    $scale = 100.0/$total;
    $cpu_load = ($d_user+$d_nice+$d_system)*$scale;
    $this->load["user"] = $d_user*$scale;
    $this->load["nice"] = $d_nice*$scale;
    $this->load["system"] = $d_system*$scale;
    $this->load["idle"] = $d_idle*$scale;
    $this->load["cpu"] = ($d_user+$d_nice+$d_system)*$scale;
    }
    function print_current() {
    printf("Current load tickers - User: %f Nice: %f System: %f Idle: %f<br/>",
    $this->user,
    $this->nice,
    $this->system,
    $this->idle
    );
    }
    function print_load() {
    printf("User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% Load: %.1f%%<br/>",
    $this->load["user"],
    $this->load["nice"],
    $this->load["system"],
    $this->load["idle"],
    $this->load["cpu"]
    );
    }
    function get_load($fastest_sample=4) {
    $this->load_load();
    $this->cached = (time()-$this->lasttime);
    if ($this->cached>=$fastest_sample) {
    $this->check_load();
    $this->calculate_load();
    $this->save_load();
    }
    }
    }

    // NOTE: Calling $cpuload->get_load() requires that your webserver has
    // write access to the /tmp directory! If it does not have access, you
    // need to edit TEMP_PATH and change the temporary directory.
    $cpuload = new CPULoad();
    $cpuload->get_load();
    $cpuload->print_load();
    $CPULOAD = round($cpuload->load["cpu"],3);

    echo "<br/>The average CPU load is: ".$CPULOAD."%\n";
    echo "<div class='progressbar'>\n";
    echo " <div style='width: ".$CPULOAD."%; background-color: rgb(0, 204, 0);' id='serviceload'>\n";
    echo " </div>\n";
    echo "</div>\n";

    echo "<br/><br/><br/>";
    $DURATION_end=microtime(true);
    $DURATION = $DURATION_end - $DURATION_start;
    echo "<p><font size='0'>Page generated in ".round($DURATION,3)." seconds</font></p>\n";
    ?>
    </p>
    </blockquote>

    </body>
    </html>[/php]


    Weitere Versionen des cpu.php stehen in Beitrag#10 sowie Beitrag#11 und derzeit letzte Version 0.9 in Beitrag#33

  • Also erst mal Tolle Arbeit
    habe die Datei mal heruntergeladen. nur wen ich "Use vcgencmd" passiert gar nicht außer die höhere CPU last??? :denker: (Weder sichtbar/ noch im Quelltext)

    Muss ich erst was auf meinem Raspi freigeben bzw rechte einräumen?

    (das ich Raspbmc Nutze dürfte dabei doch keine all zu große rolle spielen? oder)
    MFG. C. And

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (25. August 2013 um 00:38)

  • Am Anfang des php Files steht was benötigt wird damit vcgencmd genutzt werden kann:

    required /etc/sudoers entry to display GPU Temp , CPU Voltage and all other vcgencmd-values:
    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd

  • *aua*ko* ...ja jetzt sieht es aus wie bei dir :D

    Ok werde mal gucken ob ich die Tabellen geortnet dargestellt bekomme .

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

  • So ich habe folgende Lösung:

    und das PHP Script (Zeile 244 - Zeile 298) wird entfernt und das "neue" fast am ende eingefügt!
    (nach </blockquote> und vor </body>)

    dabei habe ich das DIV & die äußere Tabelle entfernt und die einzelnen Tabellen mit IDs ausgestattet!

    die Positionen der Tabellen kann man im CSS-Tag einzeln abändern.
    edit?usp=sharingBild bie G-Drive

    hoffe es sit das was du gesucht hast!

    Folgenden Text am ende des CSS-Tags einfügen:

    "Neuer" PHP teil: (Am ende nach </blockquote> und vor </body><body>)

    Und natürlich vorher eine sicherung der uhrsprünglichen Datei machen ;)
    Ps. Vermute mal das das mit meinem Bild nicht auf Anhieb geklappt hat... deshalb der Link zu Google...

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (25. August 2013 um 03:00)

  • Vorschlage Nr. 2 Ohne Tabellen als Grundgerüst! (Dieses wird jetzt aus 3 Div-Tags gebildet )
    Anmerkung habe die meisten PHP-Scripte nach oben verlagert hoffe das es nicht stört:D


    97bd35ry.jpg

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (25. August 2013 um 08:13)

  • Erstmal Danke für deine Mühe :)

    Mit den div's hatte ich auch mal probiert, allerdings gab es dann ein Problem mit dem unterschiedlichen config.txt Inhalt - jenachdem was in config.txt eingetragen wurde vergrössert sich die Tabelle und wegen position:absolute; überschneiden sich die Tabellen dann :(

    Hab dein 2.Vorschlag aber noch nicht getestet - muss erstmal wach werden :D

  • ggf die "Config-Tabelle" nach unten setzen? :D
    werde aber mal sehen ob sich das nicht automatisch lösen lässt das die automatisch nach unten rutschen :D

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (25. August 2013 um 12:38)

  • Hab das Script auch noch mal überarbeitet und etwas aufgeräumt sowie die 'sed' und 'cut' Befehle durch php-Code ersetzt:

    [code=php]<?php
    /*

    v0.5 - Written by meigrafd

    /opt/vc/bin/vcgencmd support to get detailed Infos. Warning: makes much more CPU load!

    required /etc/sudoers entry to display GPU Temp , CPU Voltage and all other vcgencmd-values:

    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd

    */
    session_start();
    session_cache_limiter(1440);
    $DURATION_start = microtime(true);
    $ERROR = "";
    $CMD = 'sudo /opt/vc/bin/vcgencmd';
    $USEvcgencmd = 0; // set 1 to default enable it
    define("TEMP_PATH","/tmp/");

    $RESET = isset($_POST["RESET"]) ? $_POST["RESET"] : "";
    $buttonUSEvcgencmd = isset($_POST["USEvcgencmd"]) ? $_POST["USEvcgencmd"] : "";

    if (!empty($buttonUSEvcgencmd)) {
    if ($buttonUSEvcgencmd == "true") { $_SESSION['vcgencmd'] = 1; }
    if ($buttonUSEvcgencmd == "false") { $_SESSION['vcgencmd'] = 0; }
    }

    if (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 1) {
    $USEvcgencmd = 1;
    } elseif (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 0) {
    $USEvcgencmd = 0;
    }

    if (!isset($vcgencmd)) { $vcgencmd=0; }

    if (!empty($RESET)) {
    if (isset($_SESSION['max_cputemp'])) { unset($_SESSION['max_cputemp']); }
    if (isset($_SESSION['min_cputemp'])) { unset($_SESSION['min_cputemp']); }
    if (isset($_SESSION['max_cpufreq'])) { unset($_SESSION['max_cpufreq']); }
    if (isset($_SESSION['min_cpufreq'])) { unset($_SESSION['min_cpufreq']); }
    if (isset($_SESSION['max_gputemp'])) { unset($_SESSION['max_gputemp']); }
    if (isset($_SESSION['min_gputemp'])) { unset($_SESSION['min_gputemp']); }
    }

    exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
    exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
    $cputemp = $cputemp[0] / 1000;
    $cpufreq = $cpufreq[0] / 1000;

    # vcgencmd command details: http://elinux.org/RPI_vcgencmd_usage
    if ($USEvcgencmd == 1) {
    @exec("".$CMD." measure_temp", $gputemp);
    if (!empty($gputemp[0])) {
    if (preg_match("/VCHI initialization failed/", $gputemp[0])) {
    $ERROR = "Error while executing '".$CMD."'! $gputemp[0]<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    } else {
    $vcgencmd = 1;
    preg_match("/.*=(.*)/", $gputemp[0], $gmatch);
    if (isset($gmatch[1])) { $gputemp[0] = str_replace("'C", "", $gmatch[1]); } else { unset($gputemp[0]); }
    unset($gmatch);
    }
    } else {
    $ERROR = "Error while executing '".$CMD."'!<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    }
    if ($vcgencmd == 1) {
    # current active volts
    $VoltTypes = "core sdram_c sdram_i sdram_p";
    $volt_list = array();
    foreach (explode(" ", $VoltTypes) AS $vt) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_volts ".$vt.""), $vmatch);
    if (isset($vmatch[1])) { $volt_list["$vt"] = $vmatch[1]; }
    unset($vmatch);
    }
    # current active settings
    exec("".$CMD." get_config int", $config_integers);
    $config_integer = array();
    foreach ($config_integers AS $integer) {
    preg_match('°(.*)=(.*)°', $integer,$int);
    if (isset($int[1]) AND !empty($int[1])) { $config_integer["$int[1]"] = $int[2]; }
    unset($int);
    }
    # current active frequency's
    $ClockTypes = "arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi";
    $clock_list = array();
    foreach (explode(" ", $ClockTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_clock ".$ct.""), $clmatch);
    if (isset($clmatch[1])) { $clock_list["$ct"] = $clmatch[1]; }
    unset($clmatch);
    }
    # current codec enabled
    $CodecTypes = "H264 MPG2 WVC1 MPG4 MJPG WMV9";
    $codec_list = array();
    foreach (explode(" ", $CodecTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." codec_enabled ".$ct.""), $cmatch);
    if (isset($cmatch[1])) { $codec_list["$ct"] = $cmatch[1]; }
    unset($cmatch);
    }
    # current mem split
    $MemTypes = "arm gpu";
    $mem_list = array();
    foreach (explode(" ", $MemTypes) AS $mt) {
    preg_match("/.*=(.*)/", exec("".$CMD." get_mem ".$mt.""), $mmatch);
    if (isset($mmatch[1])) { $mem_list["$mt"] = $mmatch[1]; }
    unset($mmatch);
    }
    }
    }

    // max cpu
    if (!isset($_SESSION['max_cputemp'])) {
    $_SESSION['max_cputemp'] = $cputemp;
    } elseif ($_SESSION['max_cputemp'] < $cputemp) {
    $_SESSION['max_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['max_cpufreq'])) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    } elseif ($_SESSION['max_cpufreq'] < $cpufreq) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    }
    // min cpu
    if (!isset($_SESSION['min_cputemp'])) {
    $_SESSION['min_cputemp'] = $cputemp;
    } elseif ($cputemp < $_SESSION['min_cputemp']) {
    $_SESSION['min_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['min_cpufreq'])) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    } elseif ($cpufreq < $_SESSION['min_cpufreq']) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    }

    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    // max gpu
    if (!isset($_SESSION['max_gputemp'])) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    } elseif ($_SESSION['max_gputemp'] < $gputemp[0]) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    }
    // min gpu
    if (!isset($_SESSION['min_gputemp'])) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    } elseif ($gputemp[0] < $_SESSION['min_gputemp']) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    }
    }

    class CPULoad {
    function check_load() {
    $fd = fopen("/proc/stat","r");
    if ($fd) {
    $statinfo = explode("\n",fgets($fd, 1024));
    fclose($fd);
    foreach($statinfo as $line) {
    $info = explode(" ",$line);
    //echo "<pre>"; var_dump($info); echo "</pre>";
    if($info[0]=="cpu") {
    array_shift($info); // pop off "cpu"
    if(!$info[0]) array_shift($info); // pop off blank space (if any)
    $this->user = $info[0];
    $this->nice = $info[1];
    $this->system = $info[2];
    $this->idle = $info[3];
    // $this->print_current();
    return;
    }
    }
    }
    }
    function store_load() {
    $this->last_user = $this->user;
    $this->last_nice = $this->nice;
    $this->last_system = $this->system;
    $this->last_idle = $this->idle;
    }
    function save_load() {
    $this->store_load();
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","w");
    if ($fp) {
    fwrite($fp,time()."\n");
    fwrite($fp,$this->last_user." ".$this->last_nice." ".$this->last_system." ".$this->last_idle."\n");
    fwrite($fp,$this->load["user"]." ".$this->load["nice"]." ".$this->load["system"]." ".$this->load["idle"]." ".$this->load["cpu"]."\n");
    fclose($fp);
    }
    }
    function load_load() {
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","r");
    if ($fp) {
    $lines = explode("\n",fread($fp,1024));
    $this->lasttime = $lines[0];
    list($this->last_user,$this->last_nice,$this->last_system,$this->last_idle) = explode(" ",$lines[1]);
    list($this->load["user"],$this->load["nice"],$this->load["system"],$this->load["idle"],$this->load["cpu"]) = explode(" ",$lines[2]);
    fclose($fp);
    } else {
    $this->lasttime = time() - 60;
    $this->last_user = $this->last_nice = $this->last_system = $this->last_idle = 0;
    $this->user = $this->nice = $this->system = $this->idle = 0;
    }
    }
    function calculate_load() {
    //$this->print_current();
    $d_user = $this->user - $this->last_user;
    $d_nice = $this->nice - $this->last_nice;
    $d_system = $this->system - $this->last_system;
    $d_idle = $this->idle - $this->last_idle;
    //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br/>",$d_user,$d_nice,$d_system,$d_idle);
    $total=$d_user+$d_nice+$d_system+$d_idle;
    if ($total<1) $total=1;
    $scale = 100.0/$total;
    $cpu_load = ($d_user+$d_nice+$d_system)*$scale;
    $this->load["user"] = $d_user*$scale;
    $this->load["nice"] = $d_nice*$scale;
    $this->load["system"] = $d_system*$scale;
    $this->load["idle"] = $d_idle*$scale;
    $this->load["cpu"] = ($d_user+$d_nice+$d_system)*$scale;
    }
    function print_current() {
    printf("Current load tickers - User: %f Nice: %f System: %f Idle: %f<br/>",
    $this->user,
    $this->nice,
    $this->system,
    $this->idle
    );
    }
    function print_load() {
    printf("User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% Load: %.1f%%<br/>",
    $this->load["user"],
    $this->load["nice"],
    $this->load["system"],
    $this->load["idle"],
    $this->load["cpu"]
    );
    }
    function get_load($fastest_sample=4) {
    $this->load_load();
    $this->cached = (time()-$this->lasttime);
    if ($this->cached>=$fastest_sample) {
    $this->check_load();
    $this->calculate_load();
    $this->save_load();
    }
    }
    }

    function showarray($array) {
    echo "<pre>\n";
    var_dump($array);
    echo "\n</pre>\n";
    flush();
    }
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title><?php echo $_SERVER['SERVER_NAME']; ?> - Informations</title>
    <meta HTTP-EQUIV=Refresh CONTENT='10'>
    <style type=text/css>

    div { border:1px solid #ccf; }

    body {
    font-size: 8pt;
    color: black;
    font-family: Verdana,arial,helvetica,serif;
    margin: 0 0 0 0;
    }
    .style1 {
    color: #999999;
    font-weight: bold;
    }
    div.progressbar {
    border: 1px solid gray;
    border-style: dotted;
    width: 40%;
    padding: 1px;
    background-color: #E0E0E0;
    margin: 0px;
    }
    div.progressbar div {
    height: 7px;
    background-color: #ff0000;
    width: 0%;
    }
    #vcgencmd {
    position:absolute;
    top:0px;
    left:700px;
    letter-spacing:0px;
    font-family:verdana, arial, helvetica, verdana, tahoma, sans-serif;
    }
    </style>
    </head>
    <body>
    <?php
    if (!empty($ERROR)) {
    $e="font-size:20px; text-align:left; color:firebrick; font-weight:bold;";
    echo "<b style='".$e."'>".$ERROR."</b><br/><br/>\n";
    }
    ?>
    <blockquote>
    <pre>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="left" valign="top">
    <form name='reset' action='' method='POST'>
    <button type='submit' value='true' name='RESET'>Reset</button>
    </form>
    </td>
    <td align="right" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='true' name='USEvcgencmd' class='USEvcgencmd'>Use vcgencmd</button>
    </form>
    </td>
    <td align="left" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='false' name='USEvcgencmd' class='USEvcgencmd'>Dont use vcgencmd</button>
    </form>
    </td>
    </tr>
    </table>
    <table border="0" cellpadding="2" cellspacing="0">
    <tr>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cputemp; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_cputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_cputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Frequence</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cpufreq; ?> MHz</td>
    <td><?php echo $_SESSION['max_cpufreq']; ?> MHz</td>
    <td><?php echo $_SESSION['min_cpufreq']; ?> MHz</td>
    </tr>
    </table>
    </td>
    <?php
    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    ?>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>GPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $gputemp[0]; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_gputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_gputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>

    <?php
    if ($vcgencmd == 1) {
    // arrays: $config_integer $volt_list $clock_list $codec_list $mem_list
    echo "<div id='vcgencmd'>\n";
    echo " <table border='0' cellpadding='2' cellspacing='0'>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>config.txt integers:</b></td></tr>\n";
    foreach ($config_integer AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Frequences:</b></td></tr>\n";
    foreach ($clock_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Codecs:</b></td></tr>\n";
    foreach ($codec_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Volts:</b></td></tr>\n";
    foreach ($volt_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'> <b>Mem-Split:</b> </td></tr>\n";
    foreach ($mem_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " </table>\n";
    echo "</div>\n";
    }
    ?>

    <span class="style1">Kernel Information:</span>
    <?php echo php_uname(); ?><br/>

    <span class="style1">Uptime:</span>
    <?php system("uptime"); ?>

    <span class="style1">Memory Usage (MB):</span>
    <?php system("free -m"); ?>

    </pre>
    <p>
    <?php
    echo "<span class='style1'>CPU Load:</span><br/>\n";
    $cpuload = new CPULoad();
    $cpuload->get_load();
    $cpuload->print_load();
    $CPULOAD = round($cpuload->load["cpu"],3);
    echo "<br/>The average CPU load is: ".$CPULOAD."%\n";
    echo "<div class='progressbar'>\n";
    echo " <div style='width: ".$CPULOAD."%; background-color: rgb(0, 204, 0);' id='serviceload'>\n";
    echo " </div>\n";
    echo "</div>\n";

    echo "<br/><br/><br/>";
    $DURATION_end = microtime(true);
    $DURATION = $DURATION_end - $DURATION_start;
    echo "<p><font size='0'>Page generated in ".round($DURATION, 3)." seconds</font></p>\n";
    ?>
    </p>
    </blockquote>

    </body>
    </html>[/php]

  • Neue Version 0.6:
    - Code aufgeräumt und ein paar mehr Checks eingebaut um Fehlermeldungen im error.log zu vermeiden
    - wenn /opt/vc/bin/vcgencmd nicht existiert werden die Buttons auch nicht angezeigt
    - Anzeige von "df -h" (Danke C.And) - Achtung: Leerzeichen im Mountpoint führen zu Fehlerhaften Anzeigen! (sollte unter Linux generell vermieden werden)
    - session_cache_limiter war falsch und wurde durch session_cache_expire ersetzt (Danke C.And)

    m4xxt2ljl9ib.png


    Version 0.6:
    http://msi.to/file/12618

    Spoiler anzeigen

    [code=php]
    <?php
    /*

    v0.6 - Written by meigrafd

    /opt/vc/bin/vcgencmd support to get detailed Infos. Warning: makes much more CPU load!

    required /etc/sudoers entry to display GPU Temp , CPU Voltage and all other vcgencmd-values:

    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd

    */
    session_start();
    session_cache_expire(1440);
    $DURATION_start = microtime(true);
    $ERROR = "";
    $CMD = 'sudo /opt/vc/bin/vcgencmd';
    $USEvcgencmd = 0; // set 1 to default enable it
    $DISPLAYfreespace = 1; // set 0 to disable
    $PageRefresh = "10"; // Refresh Page every ... Sec
    define("TEMP_PATH","/tmp/");

    $RESET = isset($_POST["RESET"]) ? $_POST["RESET"] : "";
    $buttonUSEvcgencmd = isset($_POST["USEvcgencmd"]) ? $_POST["USEvcgencmd"] : "";

    if (!empty($buttonUSEvcgencmd)) {
    if ($buttonUSEvcgencmd == "true") { $_SESSION['vcgencmd'] = 1; }
    if ($buttonUSEvcgencmd == "false") { $_SESSION['vcgencmd'] = 0; }
    }

    if (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 1) {
    $USEvcgencmd = 1;
    } elseif (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 0) {
    $USEvcgencmd = 0;
    }

    if (!isset($vcgencmd)) { $vcgencmd=0; }

    if (!empty($RESET)) {
    if (isset($_SESSION['max_cputemp'])) { unset($_SESSION['max_cputemp']); }
    if (isset($_SESSION['min_cputemp'])) { unset($_SESSION['min_cputemp']); }
    if (isset($_SESSION['max_cpufreq'])) { unset($_SESSION['max_cpufreq']); }
    if (isset($_SESSION['min_cpufreq'])) { unset($_SESSION['min_cpufreq']); }
    if (isset($_SESSION['max_gputemp'])) { unset($_SESSION['max_gputemp']); }
    if (isset($_SESSION['min_gputemp'])) { unset($_SESSION['min_gputemp']); }
    }

    exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
    exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
    $cputemp = $cputemp[0] / 1000;
    $cpufreq = $cpufreq[0] / 1000;

    # vcgencmd command details: http://elinux.org/RPI_vcgencmd_usage
    if (isset($USEvcgencmd) AND $USEvcgencmd == 1) {
    if (!file_exists("/opt/vc/bin/vcgencmd")) {
    $ERROR = "Error while executing '".$CMD."'!<br/>Cant find /opt/vc/bin/vcgencmd Shellcommand!";
    $USEvcgencmd = 0;
    } else {
    @exec("".$CMD." measure_temp", $gputemp);
    if (!empty($gputemp[0])) {
    if (preg_match("/VCHI initialization failed/", $gputemp[0])) {
    $ERROR = "Error while executing '".$CMD."'! $gputemp[0]<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    } else {
    $vcgencmd = 1;
    preg_match("/.*=(.*)/", $gputemp[0], $gmatch);
    if (isset($gmatch[1])) { $gputemp[0] = str_replace("'C", "", $gmatch[1]); } else { unset($gputemp[0]); }
    unset($gmatch);
    }
    } else {
    $ERROR = "Error while executing '".$CMD."'!<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    }
    if (isset($vcgencmd) AND $vcgencmd == 1) {
    # current active volts
    $VoltTypes = "core sdram_c sdram_i sdram_p";
    $volt_list = array();
    foreach (explode(" ", $VoltTypes) AS $vt) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_volts ".$vt.""), $vmatch);
    if (isset($vmatch[1])) { $volt_list["$vt"] = $vmatch[1]; }
    unset($vmatch);
    }
    # current active settings
    exec("".$CMD." get_config int", $config_integers);
    $config_integer = array();
    foreach ($config_integers AS $integer) {
    preg_match('°(.*)=(.*)°', $integer,$int);
    if (isset($int[1]) AND !empty($int[1])) { $config_integer["$int[1]"] = $int[2]; }
    unset($int);
    }
    # current active frequency's
    $ClockTypes = "arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi";
    $clock_list = array();
    foreach (explode(" ", $ClockTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_clock ".$ct.""), $clmatch);
    if (isset($clmatch[1])) { $clock_list["$ct"] = $clmatch[1]; }
    unset($clmatch);
    }
    # current codec enabled
    $CodecTypes = "H264 MPG2 WVC1 MPG4 MJPG WMV9";
    $codec_list = array();
    foreach (explode(" ", $CodecTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." codec_enabled ".$ct.""), $cmatch);
    if (isset($cmatch[1])) { $codec_list["$ct"] = $cmatch[1]; }
    unset($cmatch);
    }
    # current mem split
    $MemTypes = "arm gpu";
    $mem_list = array();
    foreach (explode(" ", $MemTypes) AS $mt) {
    preg_match("/.*=(.*)/", exec("".$CMD." get_mem ".$mt.""), $mmatch);
    if (isset($mmatch[1])) { $mem_list["$mt"] = $mmatch[1]; }
    unset($mmatch);
    }
    }
    }
    }

    # Display Free Space
    if (isset($DISPLAYfreespace) AND $DISPLAYfreespace == 1) {
    $FreeSpace ="<table id='FreeSpace' cellspacing='0' border='1px'>\n";
    $FreeSpace.="<tr><th colspan='6'>Free Space on: ".$_SERVER['SERVER_NAME']."</th></tr>\n";
    $FreeSpace.="<tr style='font-weight:bold; text-align:center;'>\n";
    $FreeSpace.="<td> Filesystem </td><td> Size </td><td> Used </td><td> Free </td><td> % Used </td><td> Mountpoint </td>\n";
    $FreeSpace.="</tr>\n";
    exec("df -h", $DiskFree);
    array_shift($DiskFree);
    foreach ($DiskFree AS $DFline) {
    $c=0;
    $FreeSpace.="<tr>\n";
    foreach(explode(" ",$DFline) AS $DFrow) {
    if (empty($DFrow) AND $DFrow !== "0") { continue; }
    ++$c;
    if ($c > "1" AND $c != "6" AND $pos = strpos($DFrow,".0")) {
    $prefix = substr($DFrow,-1);
    $DFrow = "".substr($DFrow,0,$pos)."".$prefix."";
    }
    if ($c > "1" AND $c < "5") {
    $DFrow = str_replace("B"," B",$DFrow);
    $DFrow = str_replace("K"," KB",$DFrow);
    $DFrow = str_replace("M"," MB",$DFrow);
    $DFrow = str_replace("G"," GB",$DFrow);
    }
    if ($c >= "2" AND $c != "6") { $td="<td style='text-align:right;'>"; } else { $td="<td>"; }
    $FreeSpace.="".$td." ".$DFrow." </td>";
    }
    $FreeSpace.="\n</tr>\n";
    }
    $FreeSpace.="</table>\n";
    }


    // max cpu
    if (!isset($_SESSION['max_cputemp'])) {
    $_SESSION['max_cputemp'] = $cputemp;
    } elseif ($_SESSION['max_cputemp'] < $cputemp) {
    $_SESSION['max_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['max_cpufreq'])) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    } elseif ($_SESSION['max_cpufreq'] < $cpufreq) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    }
    // min cpu
    if (!isset($_SESSION['min_cputemp'])) {
    $_SESSION['min_cputemp'] = $cputemp;
    } elseif ($cputemp < $_SESSION['min_cputemp']) {
    $_SESSION['min_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['min_cpufreq'])) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    } elseif ($cpufreq < $_SESSION['min_cpufreq']) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    }

    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    // max gpu
    if (!isset($_SESSION['max_gputemp'])) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    } elseif ($_SESSION['max_gputemp'] < $gputemp[0]) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    }
    // min gpu
    if (!isset($_SESSION['min_gputemp'])) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    } elseif ($gputemp[0] < $_SESSION['min_gputemp']) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    }
    }

    class CPULoad {
    function check_load() {
    $fd = fopen("/proc/stat","r");
    if ($fd) {
    $statinfo = explode("\n",fgets($fd, 1024));
    fclose($fd);
    foreach($statinfo as $line) {
    $info = explode(" ",$line);
    //echo "<pre>"; var_dump($info); echo "</pre>";
    if($info[0]=="cpu") {
    array_shift($info); // pop off "cpu"
    if(!$info[0]) array_shift($info); // pop off blank space (if any)
    $this->user = $info[0];
    $this->nice = $info[1];
    $this->system = $info[2];
    $this->idle = $info[3];
    // $this->print_current();
    return;
    }
    }
    }
    }
    function store_load() {
    $this->last_user = $this->user;
    $this->last_nice = $this->nice;
    $this->last_system = $this->system;
    $this->last_idle = $this->idle;
    }
    function save_load() {
    $this->store_load();
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","w");
    if ($fp) {
    fwrite($fp,time()."\n");
    fwrite($fp,$this->last_user." ".$this->last_nice." ".$this->last_system." ".$this->last_idle."\n");
    fwrite($fp,$this->load["user"]." ".$this->load["nice"]." ".$this->load["system"]." ".$this->load["idle"]." ".$this->load["cpu"]."\n");
    fclose($fp);
    }
    }
    function load_load() {
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","r");
    if ($fp) {
    $lines = explode("\n",fread($fp,1024));
    $this->lasttime = $lines[0];
    list($this->last_user,$this->last_nice,$this->last_system,$this->last_idle) = explode(" ",$lines[1]);
    list($this->load["user"],$this->load["nice"],$this->load["system"],$this->load["idle"],$this->load["cpu"]) = explode(" ",$lines[2]);
    fclose($fp);
    } else {
    $this->lasttime = time() - 60;
    $this->last_user = $this->last_nice = $this->last_system = $this->last_idle = 0;
    $this->user = $this->nice = $this->system = $this->idle = 0;
    }
    }
    function calculate_load() {
    //$this->print_current();
    $d_user = $this->user - $this->last_user;
    $d_nice = $this->nice - $this->last_nice;
    $d_system = $this->system - $this->last_system;
    $d_idle = $this->idle - $this->last_idle;
    //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br/>",$d_user,$d_nice,$d_system,$d_idle);
    $total=$d_user+$d_nice+$d_system+$d_idle;
    if ($total<1) $total=1;
    $scale = 100.0/$total;
    $cpu_load = ($d_user+$d_nice+$d_system)*$scale;
    $this->load["user"] = $d_user*$scale;
    $this->load["nice"] = $d_nice*$scale;
    $this->load["system"] = $d_system*$scale;
    $this->load["idle"] = $d_idle*$scale;
    $this->load["cpu"] = ($d_user+$d_nice+$d_system)*$scale;
    }
    function print_current() {
    printf("Current load tickers - User: %f Nice: %f System: %f Idle: %f<br/>",
    $this->user,
    $this->nice,
    $this->system,
    $this->idle
    );
    }
    function print_load() {
    printf("User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% Load: %.1f%%<br/>",
    $this->load["user"],
    $this->load["nice"],
    $this->load["system"],
    $this->load["idle"],
    $this->load["cpu"]
    );
    }
    function get_load($fastest_sample=4) {
    $this->load_load();
    $this->cached = (time()-$this->lasttime);
    if ($this->cached>=$fastest_sample) {
    $this->check_load();
    $this->calculate_load();
    $this->save_load();
    }
    }
    }
    # Debug
    function showarray($array) {
    echo "<pre>\n";
    var_dump($array);
    echo "\n</pre>\n";
    flush();
    }
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title><?php echo $_SERVER['SERVER_NAME']; ?> - Informations</title>
    <meta HTTP-EQUIV=Refresh CONTENT='<?php echo $PageRefresh; ?>'>
    <style type=text/css>

    div { border:1px solid #ccf; }

    body {
    font-size: 8pt;
    color: black;
    font-family: Verdana,arial,helvetica,serif;
    margin: 0 0 0 0;
    }
    .style1 {
    color: #999999;
    font-weight: bold;
    }
    div.progressbar {
    border: 1px solid gray;
    border-style: dotted;
    width: 40%;
    padding: 1px;
    background-color: #E0E0E0;
    margin: 0px;
    }
    div.progressbar div {
    height: 7px;
    background-color: #ff0000;
    width: 0%;
    }
    #vcgencmd {
    position:absolute;
    top:0px;
    left:700px;
    letter-spacing:0px;
    font-family:verdana, arial, helvetica, verdana, tahoma, sans-serif;
    }
    h2 {
    letter-spacing:2px;
    font-family: "Trebuchet MS",verdana,arial, helvetica, verdana, tahoma, sans-serif;
    font-size:24px;
    font-weight:bold;
    text-align:left;
    }
    </style>
    </head>
    <body>
    <?php
    if (isset($ERROR) AND !empty($ERROR)) {
    $e="font-size:20px; text-align:left; color:firebrick; font-weight:bold;";
    echo "<b style='".$e."'>".$ERROR."</b><br/><br/>\n";
    }
    ?>
    <blockquote>
    <pre>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="left" valign="top">
    <form name='reset' action='' method='POST'>
    <button type='submit' value='true' name='RESET'>Reset</button>
    </form>
    </td>
    <?php
    if (file_exists("/opt/vc/bin/vcgencmd")) {
    ?>
    <td align="right" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='true' name='USEvcgencmd' class='USEvcgencmd'>Use vcgencmd</button>
    </form>
    </td>
    <td align="left" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='false' name='USEvcgencmd' class='USEvcgencmd'>Dont use vcgencmd</button>
    </form>
    </td>
    <?php
    }
    ?>
    </tr>
    </table>

    <table border="0" cellpadding="2" cellspacing="0">
    <tr>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cputemp; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_cputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_cputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Frequence</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cpufreq; ?> MHz</td>
    <td><?php echo $_SESSION['max_cpufreq']; ?> MHz</td>
    <td><?php echo $_SESSION['min_cpufreq']; ?> MHz</td>
    </tr>
    </table>
    </td>
    <?php
    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    ?>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>GPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $gputemp[0]; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_gputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_gputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>

    <?php
    if (isset($DISPLAYfreespace) AND $DISPLAYfreespace == 1) { echo $FreeSpace; }

    if (isset($vcgencmd) AND $vcgencmd == 1) {
    // arrays: $config_integer $volt_list $clock_list $codec_list $mem_list
    echo "<div id='vcgencmd'>\n";
    echo " <table border='0' cellpadding='2' cellspacing='0'>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>config.txt integers:</b></td></tr>\n";
    foreach ($config_integer AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Frequences:</b></td></tr>\n";
    foreach ($clock_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Codecs:</b></td></tr>\n";
    foreach ($codec_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Volts:</b></td></tr>\n";
    foreach ($volt_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'> <b>Mem-Split:</b> </td></tr>\n";
    foreach ($mem_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " </table>\n";
    echo "</div>\n";
    }
    ?>

    <span class="style1">Kernel Information:</span>
    <?php echo php_uname(); ?><br/>

    <span class="style1">Uptime:</span>
    <?php system("uptime"); ?>

    <span class="style1">Memory Usage (MB):</span>
    <?php system("free -m"); ?>

    </pre>
    <p>
    <?php
    echo "<span class='style1'>CPU Load:</span><br/>\n";
    $cpuload = new CPULoad();
    $cpuload->get_load();
    $cpuload->print_load();
    $CPULOAD = round($cpuload->load["cpu"],3);
    echo "<br/>The average CPU load is: ".$CPULOAD."%\n";
    echo "<div class='progressbar'>\n";
    echo " <div style='width: ".$CPULOAD."%; background-color: rgb(0, 204, 0);' id='serviceload'>\n";
    echo " </div>\n";
    echo "</div>\n";

    echo "<br/><br/><br/>";
    $DURATION_end = microtime(true);
    $DURATION = $DURATION_end - $DURATION_start;
    echo "<p><font size='0'>Page generated in ".round($DURATION, 3)." seconds</font></p>\n";
    ?>
    </p>
    </blockquote>

    </body>
    </html>
    [/php]


    Version 0.7:
    (mit farblich unterschiedlichem CPU-Load Balken (Danke @ C.And)

    http://msi.to/file/69120

    Spoiler anzeigen

    [code=php]
    <?php
    /*

    v0.7 - Written by meigrafd

    /opt/vc/bin/vcgencmd support to get detailed Infos. Warning: makes much more CPU load!

    required /etc/sudoers entry to display GPU Temp , CPU Voltage and all other vcgencmd-values:

    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd

    */
    session_start();
    session_cache_expire(1440);
    $DURATION_start = microtime(true);
    $ERROR = "";
    $CMD = 'sudo /opt/vc/bin/vcgencmd';
    $USEvcgencmd = 0; // set 1 to default enable it
    $DISPLAYfreespace = 1; // set 0 to disable
    $PageRefresh = "10"; // Refresh Page every ... Sec
    define("TEMP_PATH","/tmp/");

    $RESET = isset($_POST["RESET"]) ? $_POST["RESET"] : "";
    $buttonUSEvcgencmd = isset($_POST["USEvcgencmd"]) ? $_POST["USEvcgencmd"] : "";

    if (!empty($buttonUSEvcgencmd)) {
    if ($buttonUSEvcgencmd == "true") { $_SESSION['vcgencmd'] = 1; }
    if ($buttonUSEvcgencmd == "false") { $_SESSION['vcgencmd'] = 0; }
    }

    if (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 1) {
    $USEvcgencmd = 1;
    } elseif (isset($_SESSION['vcgencmd']) AND $_SESSION['vcgencmd'] == 0) {
    $USEvcgencmd = 0;
    }

    if (!isset($vcgencmd)) { $vcgencmd=0; }

    if (!empty($RESET)) {
    if (isset($_SESSION['max_cputemp'])) { unset($_SESSION['max_cputemp']); }
    if (isset($_SESSION['min_cputemp'])) { unset($_SESSION['min_cputemp']); }
    if (isset($_SESSION['max_cpufreq'])) { unset($_SESSION['max_cpufreq']); }
    if (isset($_SESSION['min_cpufreq'])) { unset($_SESSION['min_cpufreq']); }
    if (isset($_SESSION['max_gputemp'])) { unset($_SESSION['max_gputemp']); }
    if (isset($_SESSION['min_gputemp'])) { unset($_SESSION['min_gputemp']); }
    }

    exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
    exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
    $cputemp = $cputemp[0] / 1000;
    $cpufreq = $cpufreq[0] / 1000;

    # vcgencmd command details: http://elinux.org/RPI_vcgencmd_usage
    if (isset($USEvcgencmd) AND $USEvcgencmd == 1) {
    if (!file_exists("/opt/vc/bin/vcgencmd")) {
    $ERROR = "Error while executing '".$CMD."'!<br/>Cant find /opt/vc/bin/vcgencmd Shellcommand!";
    $USEvcgencmd = 0;
    } else {
    @exec("".$CMD." measure_temp", $gputemp);
    if (!empty($gputemp[0])) {
    if (preg_match("/VCHI initialization failed/", $gputemp[0])) {
    $ERROR = "Error while executing '".$CMD."'! $gputemp[0]<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    } else {
    $vcgencmd = 1;
    preg_match("/.*=(.*)/", $gputemp[0], $gmatch);
    if (isset($gmatch[1])) { $gputemp[0] = str_replace("'C", "", $gmatch[1]); } else { unset($gputemp[0]); }
    unset($gmatch);
    }
    } else {
    $ERROR = "Error while executing '".$CMD."'!<br/>Maybe no sudo prefix or you forgot the required entry in /etc/sudoers ?";
    }
    if (isset($vcgencmd) AND $vcgencmd == 1) {
    # current active volts
    $VoltTypes = "core sdram_c sdram_i sdram_p";
    $volt_list = array();
    foreach (explode(" ", $VoltTypes) AS $vt) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_volts ".$vt.""), $vmatch);
    if (isset($vmatch[1])) { $volt_list["$vt"] = $vmatch[1]; }
    unset($vmatch);
    }
    # current active settings
    exec("".$CMD." get_config int", $config_integers);
    $config_integer = array();
    foreach ($config_integers AS $integer) {
    preg_match('°(.*)=(.*)°', $integer,$int);
    if (isset($int[1]) AND !empty($int[1])) { $config_integer["$int[1]"] = $int[2]; }
    unset($int);
    }
    # current active frequency's
    $ClockTypes = "arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi";
    $clock_list = array();
    foreach (explode(" ", $ClockTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." measure_clock ".$ct.""), $clmatch);
    if (isset($clmatch[1])) { $clock_list["$ct"] = $clmatch[1]; }
    unset($clmatch);
    }
    # current codec enabled
    $CodecTypes = "H264 MPG2 WVC1 MPG4 MJPG WMV9";
    $codec_list = array();
    foreach (explode(" ", $CodecTypes) AS $ct) {
    preg_match("/.*=(.*)/", exec("".$CMD." codec_enabled ".$ct.""), $cmatch);
    if (isset($cmatch[1])) { $codec_list["$ct"] = $cmatch[1]; }
    unset($cmatch);
    }
    # current mem split
    $MemTypes = "arm gpu";
    $mem_list = array();
    foreach (explode(" ", $MemTypes) AS $mt) {
    preg_match("/.*=(.*)/", exec("".$CMD." get_mem ".$mt.""), $mmatch);
    if (isset($mmatch[1])) { $mem_list["$mt"] = $mmatch[1]; }
    unset($mmatch);
    }
    }
    }
    }

    # Display Free Space
    if (isset($DISPLAYfreespace) AND $DISPLAYfreespace == 1) {
    $FreeSpace ="<table id='FreeSpace' cellspacing='0' border='1px'>\n";
    $FreeSpace.="<tr><th colspan='6'>Free Space on: ".$_SERVER['SERVER_NAME']."</th></tr>\n";
    $FreeSpace.="<tr style='font-weight:bold; text-align:center;'>\n";
    $FreeSpace.="<td> Filesystem </td><td> Size </td><td> Used </td><td> Free </td><td> % Used </td><td> Mountpoint </td>\n";
    $FreeSpace.="</tr>\n";
    exec("df -h", $DiskFree);
    array_shift($DiskFree);
    foreach ($DiskFree AS $DFline) {
    $c=0;
    $FreeSpace.="<tr>\n";
    foreach(explode(" ",$DFline) AS $DFrow) {
    if (empty($DFrow) AND $DFrow !== "0") { continue; }
    ++$c;
    if ($c > "1" AND $c != "6" AND $pos = strpos($DFrow,".0")) {
    $prefix = substr($DFrow,-1);
    $DFrow = "".substr($DFrow,0,$pos)."".$prefix."";
    }
    if ($c > "1" AND $c < "5") {
    $DFrow = str_replace("B"," B",$DFrow);
    $DFrow = str_replace("K"," KB",$DFrow);
    $DFrow = str_replace("M"," MB",$DFrow);
    $DFrow = str_replace("G"," GB",$DFrow);
    }
    if ($c >= "2" AND $c != "6") { $td="<td style='text-align:right;'>"; } else { $td="<td>"; }
    $FreeSpace.="".$td." ".$DFrow." </td>";
    }
    $FreeSpace.="\n</tr>\n";
    }
    $FreeSpace.="</table>\n";
    }


    // max cpu
    if (!isset($_SESSION['max_cputemp'])) {
    $_SESSION['max_cputemp'] = $cputemp;
    } elseif ($_SESSION['max_cputemp'] < $cputemp) {
    $_SESSION['max_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['max_cpufreq'])) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    } elseif ($_SESSION['max_cpufreq'] < $cpufreq) {
    $_SESSION['max_cpufreq'] = $cpufreq;
    }
    // min cpu
    if (!isset($_SESSION['min_cputemp'])) {
    $_SESSION['min_cputemp'] = $cputemp;
    } elseif ($cputemp < $_SESSION['min_cputemp']) {
    $_SESSION['min_cputemp'] = $cputemp;
    }
    if (!isset($_SESSION['min_cpufreq'])) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    } elseif ($cpufreq < $_SESSION['min_cpufreq']) {
    $_SESSION['min_cpufreq'] = $cpufreq;
    }

    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    // max gpu
    if (!isset($_SESSION['max_gputemp'])) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    } elseif ($_SESSION['max_gputemp'] < $gputemp[0]) {
    $_SESSION['max_gputemp'] = $gputemp[0];
    }
    // min gpu
    if (!isset($_SESSION['min_gputemp'])) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    } elseif ($gputemp[0] < $_SESSION['min_gputemp']) {
    $_SESSION['min_gputemp'] = $gputemp[0];
    }
    }

    class CPULoad {
    function check_load() {
    $fd = fopen("/proc/stat","r");
    if ($fd) {
    $statinfo = explode("\n",fgets($fd, 1024));
    fclose($fd);
    foreach($statinfo as $line) {
    $info = explode(" ",$line);
    //echo "<pre>"; var_dump($info); echo "</pre>";
    if($info[0]=="cpu") {
    array_shift($info); // pop off "cpu"
    if(!$info[0]) array_shift($info); // pop off blank space (if any)
    $this->user = $info[0];
    $this->nice = $info[1];
    $this->system = $info[2];
    $this->idle = $info[3];
    // $this->print_current();
    return;
    }
    }
    }
    }
    function store_load() {
    $this->last_user = $this->user;
    $this->last_nice = $this->nice;
    $this->last_system = $this->system;
    $this->last_idle = $this->idle;
    }
    function save_load() {
    $this->store_load();
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","w");
    if ($fp) {
    fwrite($fp,time()."\n");
    fwrite($fp,$this->last_user." ".$this->last_nice." ".$this->last_system." ".$this->last_idle."\n");
    fwrite($fp,$this->load["user"]." ".$this->load["nice"]." ".$this->load["system"]." ".$this->load["idle"]." ".$this->load["cpu"]."\n");
    fclose($fp);
    }
    }
    function load_load() {
    $fp = @fopen(TEMP_PATH."cpuinfo.tmp","r");
    if ($fp) {
    $lines = explode("\n",fread($fp,1024));
    $this->lasttime = $lines[0];
    list($this->last_user,$this->last_nice,$this->last_system,$this->last_idle) = explode(" ",$lines[1]);
    list($this->load["user"],$this->load["nice"],$this->load["system"],$this->load["idle"],$this->load["cpu"]) = explode(" ",$lines[2]);
    fclose($fp);
    } else {
    $this->lasttime = time() - 60;
    $this->last_user = $this->last_nice = $this->last_system = $this->last_idle = 0;
    $this->user = $this->nice = $this->system = $this->idle = 0;
    }
    }
    function calculate_load() {
    //$this->print_current();
    $d_user = $this->user - $this->last_user;
    $d_nice = $this->nice - $this->last_nice;
    $d_system = $this->system - $this->last_system;
    $d_idle = $this->idle - $this->last_idle;
    //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br/>",$d_user,$d_nice,$d_system,$d_idle);
    $total=$d_user+$d_nice+$d_system+$d_idle;
    if ($total<1) $total=1;
    $scale = 100.0/$total;
    $cpu_load = ($d_user+$d_nice+$d_system)*$scale;
    $this->load["user"] = $d_user*$scale;
    $this->load["nice"] = $d_nice*$scale;
    $this->load["system"] = $d_system*$scale;
    $this->load["idle"] = $d_idle*$scale;
    $this->load["cpu"] = ($d_user+$d_nice+$d_system)*$scale;
    }
    function print_current() {
    printf("Current load tickers - User: %f Nice: %f System: %f Idle: %f<br/>",
    $this->user,
    $this->nice,
    $this->system,
    $this->idle
    );
    }
    function print_load() {
    printf("User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% Load: %.1f%%<br/>",
    $this->load["user"],
    $this->load["nice"],
    $this->load["system"],
    $this->load["idle"],
    $this->load["cpu"]
    );
    }
    function get_load($fastest_sample=4) {
    $this->load_load();
    $this->cached = (time()-$this->lasttime);
    if ($this->cached>=$fastest_sample) {
    $this->check_load();
    $this->calculate_load();
    $this->save_load();
    }
    }
    }

    function print_LoadColor($x) {
    if ($x >= 90) { return "#FF0000"; }
    elseif (($x >= 70) && ($x <= 89)) { return "#FF4000"; }
    elseif (($x >= 60) && ($x <= 69)) { return "#FF8000"; }
    elseif (($x >= 50) && ($x <= 59)) { return "#FFBF00"; }
    elseif (($x >= 30) && ($x <= 49)) { return "#FFFF00"; }
    elseif (($x >= 20) && ($x <= 29)) { return "#BFFF00"; }
    elseif (($x >= 10) && ($x <= 19)) { return "#80FF00"; }
    else { return "#00FF00"; }
    }
    # Debug
    function showarray($array) {
    echo "<pre>\n";
    var_dump($array);
    echo "\n</pre>\n";
    flush();
    }
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title><?php echo $_SERVER['SERVER_NAME']; ?> - Informations</title>
    <meta HTTP-EQUIV=Refresh CONTENT='<?php echo $PageRefresh; ?>'>
    <style type=text/css>

    div { border:1px solid #ccf; }

    body {
    font-size: 8pt;
    color: black;
    font-family: Verdana,arial,helvetica,serif;
    margin: 0 0 0 0;
    }
    .style1 {
    color: #999999;
    font-weight: bold;
    }
    div.progressbar {
    border: 1px solid gray;
    border-style: dotted;
    width: 40%;
    padding: 1px;
    background-color: #E0E0E0;
    margin: 0px;
    }
    div.progressbar div {
    height: 11px;
    background-color: #ff0000;
    width: 0%;
    }
    #vcgencmd {
    position:absolute;
    top:0px;
    left:700px;
    letter-spacing:0px;
    font-family:verdana, arial, helvetica, verdana, tahoma, sans-serif;
    }
    h2 {
    letter-spacing:2px;
    font-family: "Trebuchet MS",verdana,arial, helvetica, verdana, tahoma, sans-serif;
    font-size:24px;
    font-weight:bold;
    text-align:left;
    }
    </style>
    </head>
    <body>
    <?php
    if (isset($ERROR) AND !empty($ERROR)) {
    $e="font-size:20px; text-align:left; color:firebrick; font-weight:bold;";
    echo "<b style='".$e."'>".$ERROR."</b><br/><br/>\n";
    }
    ?>
    <blockquote>
    <pre>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="left" valign="top">
    <form name='reset' action='' method='POST'>
    <button type='submit' value='true' name='RESET'>Reset</button>
    </form>
    </td>
    <?php
    if (file_exists("/opt/vc/bin/vcgencmd")) {
    ?>
    <td align="right" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='true' name='USEvcgencmd' class='USEvcgencmd'>Use vcgencmd</button>
    </form>
    </td>
    <td align="left" valign="top">
    <form name='vcgencmd' action='' method='POST'>
    <button type='submit' value='false' name='USEvcgencmd' class='USEvcgencmd'>Dont use vcgencmd</button>
    </form>
    </td>
    <?php
    }
    ?>
    </tr>
    </table>

    <table border="0" cellpadding="2" cellspacing="0">
    <tr>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cputemp; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_cputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_cputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>CPU Frequence</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $cpufreq; ?> MHz</td>
    <td><?php echo $_SESSION['max_cpufreq']; ?> MHz</td>
    <td><?php echo $_SESSION['min_cpufreq']; ?> MHz</td>
    </tr>
    </table>
    </td>
    <?php
    if (isset($vcgencmd) AND $vcgencmd == 1 AND isset($gputemp[0])) {
    ?>
    <td>
    <table border="1" cellpadding="5" cellspacing="0">
    <tr align="center" valign="middle"><td colspan="3"><b>GPU Temperature</b></td></tr>
    <tr align="center" valign="middle"><td>Current</td> <td>Max</td> <td>Min</td></tr>
    <tr>
    <td><?php echo $gputemp[0]; ?> &deg;C</td>
    <td><?php echo $_SESSION['max_gputemp']; ?> &deg;C</td>
    <td><?php echo $_SESSION['min_gputemp']; ?> &deg;C</td>
    </tr>
    </table>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>

    <?php
    if (isset($DISPLAYfreespace) AND $DISPLAYfreespace == 1) { echo $FreeSpace; }

    if (isset($vcgencmd) AND $vcgencmd == 1) {
    // arrays: $config_integer $volt_list $clock_list $codec_list $mem_list
    echo "<div id='vcgencmd'>\n";
    echo " <table border='0' cellpadding='2' cellspacing='0'>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>config.txt integers:</b></td></tr>\n";
    foreach ($config_integer AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Frequences:</b></td></tr>\n";
    foreach ($clock_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Codecs:</b></td></tr>\n";
    foreach ($codec_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'><b>Volts:</b></td></tr>\n";
    foreach ($volt_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo " <td>\n";
    echo " <table border='1' cellspacing='0'>\n";
    echo " <tr align='center' valign='middle'><td colspan='2'> <b>Mem-Split:</b> </td></tr>\n";
    foreach ($mem_list AS $type => $int) {
    echo " <tr><td> ".$type." </td> <td> ".$int." </td></tr>\n";
    }
    echo " </table>\n";
    echo " </td>\n";
    echo " </tr>\n";
    echo " </table>\n";
    echo "</div>\n";
    }
    ?>

    <span class="style1">Kernel Information:</span>
    <?php echo php_uname(); ?><br/>

    <span class="style1">Uptime:</span>
    <?php system("uptime"); ?>

    <span class="style1">Memory Usage (MB):</span>
    <?php system("free -m"); ?>

    </pre>
    <p>
    <?php
    echo "<span class='style1'>CPU Load:</span><br/>\n";
    $cpuload = new CPULoad();
    $cpuload->get_load();
    $cpuload->print_load();
    $CPULOAD = round($cpuload->load["cpu"],3);
    echo "<br/>The average CPU load is: ".$CPULOAD."%\n";
    echo "<div class='progressbar'>\n";
    echo " <div style='width: ".$CPULOAD."%; background-color: ".print_LoadColor($CPULOAD).";' id='serviceload'>\n";
    echo " </div>\n";
    echo "</div>\n";

    echo "<br/><br/><br/>";
    $DURATION_end = microtime(true);
    $DURATION = $DURATION_end - $DURATION_start;
    echo "<p><font size='0'>Page generated in ".round($DURATION, 3)." seconds</font></p>\n";
    ?>
    </p>
    </blockquote>

    </body>
    </html>
    [/php]

  • Das dämliche Ausrichten der Tabellen frustet mich zZt also bastel ich lieber ein bischen weiter... ;)

    Und zwar bastel ich aktuell an einem Graphen für (erstmal nur) die CPU Temperatur


    Vorraussetzungen:

    Code
    apt-get update
    apt-get install sqlite3 bc php5-sqlite

    Ausserdem muss JPGraph installiert werden.
    Herunterladen, auf den RaspberryPI ins Verzeichnis /var/www/ transferieren (zB mit WinSCP) und mit tar xfz jpgraph-3.5.0b1.tar.gz entpacken.
    Ausserdem das machen was hier beschrieben wird: https://www.forum-raspberrypi.de/Thread-jpgraph?pid=29228#pid29228


    Dann habe ich mir ein tmpfs Verzeichnis angelegt wo ein SQLite Datenbank-File drin liegt (damit nicht ständig auf der SD herrum geschrieben wird)

    Code
    mkdir /var/db
    mount -t tmpfs tmpfs -o size=10M /var/db


    ACHTUNG: Nach einem Reboot o.ä. ist tmpfs leer also das Datenbankfile weg

    Dann lege ich ein bash Script an: /root/cpugraph.sh

    Script ausführbar machen:chmod +x /root/cpugraph.sh
    Und zur Probe einmal ausführen ob es auch macht was es soll: bash -x /root/cpugraph.sh
    (-x sorgt für Debug-Ausgabe)

    Dann einmal die SQLite Datenbank-Datei kontrollieren:

    Code
    sqlite3 /var/db/sqlite.sysinfos "SELECT * FROM sysinfos WHERE 1"

    Und in die Benutzer-Crontab eintragen sodass es jede Minute ausgeführt wird: crontab -e

    Code
    * * * * *       /root/cpugraph.sh >/dev/null 2>&1

    Dann die Datei /var/www/cpugraph.php erstellen:[code=php]
    <?php
    // v0.2
    include ("jpgraph-3.5.0b1/src/jpgraph.php");
    include ("jpgraph-3.5.0b1/src/jpgraph_line.php");
    require_once("jpgraph-3.5.0b1/src/jpgraph_date.php");

    $DBfile = "/var/db/sqlite.sysinfos";
    $DBtable = "sysinfos";

    //------------------------------------------------------------------------------

    $db = db_con($DBfile);
    $query = $db->query("SELECT time,cputemp FROM ".$DBtable." WHERE 1");
    $i=0;
    while($result = $query->fetch(PDO::FETCH_ASSOC)){
    $TIME[$i] = $result['time'];
    $CPUTEMP[$i] = $result['cputemp'];
    $i++;
    }

    // Create the graph.
    $graph = new Graph(1000,350,"auto");
    $graph->SetScale("datlin");

    // Create the linear plot
    // CPU Temp
    $lineplot=new LinePlot($CPUTEMP,$TIME);
    $lineplot->SetColor("red");
    $lineplot->SetWeight(2);
    $lineplot->SetLegend("CPU temp");

    // Add the plot to the graph
    $graph->Add($lineplot);

    $graph->SetShadow();
    $graph->SetMargin(40,20,20,40);
    $graph->title->Set('Datum: '.date('Y-m-d',time()));
    #$graph->xaxis->title->set("Zeit");
    #$graph->yaxis->title->Set("Temperatur °C");
    $graph->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

    $graph->xaxis->SetLabelFormatString('H:i', true);
    $graph->xaxis->SetLabelAngle(90);

    // Adjust the legend position
    #$graph->legend->Pos(0.01,0.3,"right","center");

    // Display the graph
    $graph->Stroke();


    //______________________________________________________________________________________
    // sqlite

    // DB connect
    function db_con($DBfile) {
    if (!$db = new PDO("sqlite:$DBfile")) {
    $e="font-size:23px; text-align:left; color:firebrick; font-weight:bold;";
    echo "<b style='".$e."'>Fehler beim öffnen der Datenbank:</b><br/>";
    echo "<b style='".$e."'>".$db->errorInfo()."</b><br/>";
    die;
    }
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $db;
    }

    //Function to handle database errors
    function db_error($sql,$error) {
    die('<small><font color="#ff0000"><b>[DB ERROR]</b></font></small><br/><br/><font color="#800000"><b>'.$error.'</b><br/><br/>'.$sql.'</font>');
    }
    ?>
    [/php]

    Das Ergebnis sieht dann so aus:

    Spoiler anzeigen


    nyvx2548gcm4.png

  • und ich einen Bargraph für den "Free Space" :D für meine Variante ist er schon fertig (in color). danach guck ich ob ich ihn auch für deine zusammen gebaut kriege ;) wenn du willst!?

    Vorschau Bild:

    Spoiler anzeigen


    st7i5ibq.jpg

    der Grausige Hintergrund ist auch weg!

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (29. August 2013 um 20:33)

  • Das ist ja wohl ein Muss *klein bissen angeb:)

    aber gar nicht so schwer... Kleine Spielerei

    Spoiler anzeigen

    Rechtschreibfehler sind Special Effects meiner Tastatur
    [font="Arial"]Pater dimitte illis non enim sciunt quid faciunt![/font]
    @sagte der Pi bevor er in Rauch auf ging:@
    Vater, vergib ihnen den sie Wissen nicht was sie tun!

    Einmal editiert, zuletzt von C.And (29. August 2013 um 20:52)

  • Findet die Zeit wo ich zubett und wieder aufgestanden bin

    jaase32uypij.png
    :D


    PS: Die SQLite Datenbank beinhaltet mittlerweile 994 Einträge aber ist nur 19456 Bytes ( ca. 20kB ) gross, bei einer Uptime von 17h 50min

  • Erstmal hallo an Alle!

    Sehr cooles Projekt was du da auf die Beine gestellt hast. Vorallem ist es sehr nett, dass du uns das Programm auch zur Verfügung stellst.

    Nur eine Frage habe ich. Wie genau bekomm ich das ganze bei mir ans laufen? Eine Noobie Anleitung wäre da super!:D

    Schönen Dank und Grüße!

  • Eigentlich ist das relativ einfach - das was zum nutzen vom /opt/vc/bin/vcgencmd Befehl benötigt wird steht oben im php file..

    Aber hier noch mal "noob freundlicher" :)


    Voraussetzung ist ein Webserver wie zB apache2 mit PHP:

    Code
    apt-get install apache2 php5

    In der Konsole über zB PuTTY eine neue Datei erstellen: nano /var/www/cpu.php
    ..Mit dem Inhalt des PHP-codes..

    Alternativ die Datei herunter laden und via zB WinSCP auf den RaspberryPI schieben..


    Wer den /opt/vc/bin/vcgencmd Befehl ebenfals nutzen möchte um die GPU sowie config.txt Werte anzuzeigen benötigt auch noch eine Anpassung von sudo
    (Voraussetzung ist das sudo installiert ist: apt-get install sudo)
    Damit nachfolgender Befehl über nano geöffnet wird, folgenden Befehl ein mal ausführen (ist nur einmalig nötig): export EDITOR=nano

    Code
    visudo

    Und dort folgendes ans Ende einfügen:

    Code
    www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmd


    Anschliesend die IP des RaspberryPI's ansurfen und die cpu.php aufrufen:

    Code
    http://raspberry.ip/cpu.php
  • Hallo,
    besten Dank für die gute Anleitung. Die Seite sieht wirklich klasse aus. Alles was man braucht auf einen Blick.
    Tolle Arbeit. Ich habe es mal in meine einfache Webseite (Anfänger) eingefügt und es funktioniert.
    Meine Frage: Wie viele Nutzer können eigentlich die Seite gleichzeitig aufrufen?
    Kann sich der Raspi dabei "aufhängen"?

    Gruß, woddy

  • Jeder Benutzer der die Seite aufruft startet eine eigene Session, es könnten also theoretisch unendlich viele gleichzeitig drauf zugreifen :)

    Aufhängen in dem Sinne ist eigentlich nicht möglich - das einzige was passieren kann ist das er langsamer reagiert wenn die CPU Auslastung extrem hoch ist dann brauch die cpu.php eben etwas länger die Daten zu ermitteln

    Im Chat wurde auch schon versucht meinen RaspberryPI rev1 der bei EDIS läuft, an seine Grenzen zu bringen indem schätzungsweise 10 User die cpu.php mit "Use vcgencmd" aufgerufen und ständig refresht haben - aber mehr als "CPU Load 100%" und besagtes "verzögertes reagieren" sowie Erhöhung der CPU Temperatur wurde nicht erreicht :D

    Aktuell tobt sich auch wieder ein User an ihm aus und versucht ihn "zu beeinflussen" ;)

    Wer auch sein 'Glück' versuchen will kann dies gerne selber testen -> http://151.236.12.78/cpu.php

  • Super Ding! Jedoch finde ich das Script etwas unleserlich. Also von der Einrückung. Aber egal.
    Das Script darf weiterverarbeitet werden bzw. ausschnitte den Scriptes benutzt werden? .. :P

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!