Translations of this page:
  • English (USA)

How to show estats

This is the example file index.php for showing an estats file with PHP and gd-lib (gfx-lib for php). Please create a temporary directory for the graphics file called temp.

<?php
session_start();
/*

        sll_estats.php - Auswertung der Sim-Statistik

*/

// estats file to use
//
$DATEINAME = "San.csv";

// BREITE UND HOEHE DER STATISTIK
//
$width=1024;
$height=400;

// Variablen lokal verfuegbar machen
?>
<html>
<head>
</head>

<body>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
<!-- body, td, th, h1, h2 { font-family: Trebuchet MS; } -->
td { border-width:0px; border-color:#000000; border-style:solid; padding:0px; padding-left:10px; padding-right:10px; margin:0px; }
.mytd { background-image:url('blank.gif'); border-width:2px; border-color:navy; border-style:dotted; padding:0px; padding-left:0px; padding-right:0px; margin
:0px; }

.teaser {
    margin:  0.0em 0;
    letter-spacing: .05em;
    background: #eeeeff;
    border: 1px dotted navy;
}

</style>
<?php

// Werte
//
$W[0]="Incoming BPS";
$W[1]="Outgoing BPS";
$W[2]="Script-Time";
$W[3]="ResentPackets";
$W[4]="FPS";
$W[5]="Dilation";
$W[6]="Frame-Time";
$W[7]="Physics-Time";
$W[8]="Unacked-Bytes";
$W[9]="Active-Scripts";
$W[10]="Agents";
$W[11]="Objects";
$W[12]="Memory";
$W[13]="Threads";
$W[14]="CPU";
$W[15]="Uptime";
$W[16]="Agent-Time";
$W[17]="Agent-Updates";
$W[18]="Child-Agents";
$W[19]="Received-Resents";
$W[20]="Missed-Pings";
$W[21]="Net-Time";
$W[22]="Other-Time";
$W[23]="Image-Time";
$W[24]="Physics-FPS";
$W[25]="VirtualSize";
$W[26]="Last-Lag";
$W[27]="In-PPS";
$W[28]="Out-PPS";
$W[29]="Avatar-Balance";
$W[30]="Virtual Memory";
$W[31]="Complete Prims";
$W[32]="Prim-Objects";
$W[33]="Avatar Attachments";
$W[34]="Avatar Attachment-Prims";
$W[35]="Avatars in sight";
$W[36]="Avatars online";

if (!file_exists($DATEINAME)) { echo "Fehler: Die Datei ".$DATEINAME." existiert nicht!"; die; }
if (!file_exists("temp")) { echo "Fehler: Das Verzeichnis <b>temp</b> existiert nicht!"; die; }
if (!@fopen("temp/foo.bar", w))
{
    echo "Fehler: Das Verzeichnis <b>temp</b> ist nicht schreibbar!";
    die;
}
if ($_POST[WERT]!="") { $_SESSION[WERT]=$_POST[WERT]; }

// Statistik 1
//
if ($_SESSION[WERT]=="") { $_SESSION[WERT]=0; }

$LEGENDE[0]="The line shows \"".$W[$_SESSION[WERT]]."\"";

// Anzahl der Logfileeintraege auf einer Seite
//
if ($_GET[anz]=="") { $anz=20; } else { $anz=$_GET[anz]; }

if ($_GET[anfang]=="") { $_GET[anfang]=$anzahl_gesamt-$anz; }
if ($_GET[anfang]<0) { $_GET[anfang]=0; }

$offset_minus=$_GET[anfang]-$anz;
if ($offset_minus<0) { $offset_minus=0; }
$offset_plus=$_GET[anfang]+$anz;

$fd=fopen($DATEINAME, r);
$c=0;

while ($fd && !feof($fd)) {

    $buffer=fgets($fd, 1024);

    if (substr($buffer, 0, 4) == "Date") { continue; }
    if ($buffer=="") { continue; }

//      echo $c."=".$buffer."<br>";

    $exp=explode(";", $buffer);

    $line[0][$c]=(int)str_replace(",",".",$exp[$_SESSION[WERT]+1]);
    $line["date"][$c]=$exp[0];

    $c++;
}
$WERTE=1;
$anzahl=$c;


// PUFFER
$px=80;
$py=150;

// INITIAL X
$ix=50;

// INITIAL Y
$iy=25;

// FARB WERTE FESTSETZEN
$col[0][0]=10;
$col[0][1]=100;
$col[0][2]=0;

$col[1][0]=0;
$col[1][1]=0;
$col[1][2]=255;

$col[2][0]=100;
$col[2][1]=200;
$col[2][2]=0;

$col[3][0]=255;
$col[3][1]=0;
$col[3][2]=0;

// DIVISION BY ZERO ABFANGEN
if ($anzahl==0) { $anzahl=1; }

// ABSTAND BERECHNEN
$abstand=($width-$ix)/($anzahl-1);

// BILD ERZEUGEN
$image=imagecreate($width+$px,$height+$py);

// HINTERGRUNDFARBE BESTIMMEN
$background_color = ImageColorAllocate ($image, 240, 240, 240);

// EINHEITEN FARBE BESTIMMEN
$bar_color = ImageColorAllocate($image, 0, 0, 0);
// EINHEITEN FARBE BESTIMMEN
$bar_grey = ImageColorAllocate($image, 200, 200, 200);

// DEN HOECHSTEN WERT VON ALLEN RAUSFINDEN
$big = 0;

for ($a=0; $a<count($line[0]); $a++) {
    if ($line[0][$a] > $big) { $big = $line[0][$a]; }
}

//$dotted=array("-1,0", "0,1", "1,0", "0,-1", "1,1", "-1,1", "-1,-1", "1,-1",    "-2,0","0,2","2,0","0,-2", "2,2", "-2,2", "-2,-2", "2,-2");

// EINHEITEN AN DEN RAND SCHREIBEN
$r=$width-$ix;

// + LINKS UNTEN NACH LINKS OBEN
imageline($image,$ix,$height+$iy,$ix,1+$iy,$bar_color);
imageline($image,$ix+$r,$height+$iy,$ix+$r,1+$iy,$bar_color);

// ++ LINKS UNTEN NACH RECHTS UNTEN
imageline($image,$ix,$height+$iy,$width-$ix,$height+$iy,$bar_color);

// Big Korrektur
//
if ($big < 1) { $big=1; }

// ++ EINHEITEN ++
for ($a=0; $a<=$big; $a+=1) {

        // WIEVIEL PROZENT IST DER WERT VON BIG ?
        if ($big==0) { $big=1; }
        $prozent_big=$a/$big*100;

        // WIE HOCH IST DER PROZENTWERT VON DER HOEHE ?
        $y_pos=$height/100*$prozent_big;

        if ($y_pos-$y_pos_drawn>10 || $a==0) {

            // HORIZONTALE LINIE
            imageline($image,$ix-5,$height-$y_pos+$iy,$ix+5,$height-$y_pos+$iy,$bar_color);

            // BESCHRIFTUNG
            imagestring ($image, 1, $ix-30, $height-$y_pos-3+$iy, $a, $bar_color);

            // HORIZONTALE LINIE
            imageline($image,$ix-5+$r,$height-$y_pos+$iy,$ix+5+$r,$height-$y_pos+$iy,$bar_color);

            // BESCHRIFTUNG
            imagestring ($image, 1, $ix+20+$r, $height-$y_pos-3+$iy, $a, $bar_color);

            imageline($image,$ix+6,$height-$y_pos+$iy,$ix+$r-6,$height-$y_pos+$iy,$bar_grey);


            $y_pos_drawn=$y_pos;
        }
}

// DIE GROSSE ARRAY SCHLEIFE
for ($b=0; $b<$WERTE; $b++) {

    // FARBE AUS FARBARRAY HOLEN
    $text_color = ImageColorAllocate ($image, $col[$b][0], $col[$b][1], $col[$b][2]);

    for ($a=0; $a<count($line[0]); $a++) {

        // WIEVIEL PROZENT IST DER WERT VON BIG ?
        $prozent_big=$line[$b][$a]/$big*100;

        // WIE HOCH IST DER PROZENTWERT VON DER HOEHE ?
        $y_prozent=$height/100*$prozent_big;

        // WENN ERSTER PIXEL, DANN KEINE LINIE, NUR MERKEN
        if ($a>0) {
            imageline($image,$x+$ix,$y+$iy,$ix+intval($a*$abstand),($height-$y_prozent+$iy),$text_color);

                /*
                for ($c=0; $c<count($dotted); $c++) {
                        $dotted_exp=explode(",", $dotted[$c]);
                        $x=((intval($a*$abstand))+$ix+$dotted_exp[0]);
                        $y=(($height-$y_prozent)+$iy+$dotted_exp[1]);
                        imagesetpixel($image, $x, $y, $text_color);
                }
                */
        }
        else
        {
                /*
                for ($c=0; $c<count($dotted); $c++) {
                        $dotted_exp=explode(",", $dotted[$c]);
                        $x=((intval($a*$abstand))+$ix+$dotted_exp[0]);
                        $y=(($height-$y_prozent)+$iy+$dotted_exp[1]);
                        imagesetpixel($image, $x, $y, $text_color);
                }
                */
        }
        // UNTERE BESCHRIFTUNG
        //
        if ($b==0) {
            if (intval($a*$abstand)>($xview+50)) {
                $exp=explode(" ", $line["date"][$a]);
                imagestring ($image, 1, intval($a*$abstand)+$ix-19, $height+10+$iy, str_replace(date(Y)."-","",$exp[0]), $bar_color);
                imagestring ($image, 1, intval($a*$abstand)+$ix-19, $height+20+$iy, $exp[1], $bar_color);
                $xview=intval($a*$abstand);
            }
        }

        $x=intval($a*$abstand);
        $y=($height-$y_prozent);
    }


    // BESCHRIFTUNG
    if ($b==0) { $text=$LEGENDE[0]; }
    imagestring($image, 1, $ix, $height+($b*10)+50+$iy, $text, $text_color);
}

// Bild auf Platte schreiben
//
imagepng($image, "temp/".session_id().".png");

// Bild anzeigen
//
echo "<form method=POST action='$_SERVER[PHP_SELF]' name='formular' name='formular2'>";
echo "What to display? <select name='WERT' onChange='this.form.submit();'>";
for ($a=0; $a<count($W); $a++)
{
    echo "<option value='$a' ";
    if ($a==$_SESSION[WERT]) { echo " selected"; }
    echo ">$W[$a]</option>";
}
echo "</select>";
echo " <input type='submit' value='View'>";
echo "</form>";

echo "<img src='temp/".session_id().".png?r=".date(U)."'>";

?>

howtos/how_do_you_show_estats.txt · Last modified: 2009/03/23 13:10 by eves
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0