Difference between revisions of "Sim Performance Collector (Web-based"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎Introduction: better readability on narrower screens)
Line 18: Line 18:


<lsl>
<lsl>
float  currentTimeDilation;


integer Count; // counter for averaging FPS
integer currentFPS;
integer FPS_Total; // total fps for averaging
integer totalFPS;
key SimStatusQuery;
float  averageFPS;
string simstatus//Needed to show Simstatus on Website
 
string RegName = "";
integer numberOfUpdates;
string url_inform;
 
string website = "http://www.yourdomainhere.de/php/write_rrd.php";
string regionName;
string avg;
string server;
string fps_condition;
 
string dil_cond;
string simstatus;
string s_count;
 
string server;
key    simStatusReqId;
float TimeDil;
string postReqId;
 
string website;
 
init()
{
    website = "http://www.yourdomainhere.com/php/write_rrd.php";
 
    update_data();
 
//  every minute
    llSetTimerEvent(60.0);
}
 
update_data()
{
//  increment counter...
    ++numberOfUpdates;
 
    regionName          = llGetRegionName();
    currentTimeDilation = llGetRegionTimeDilation();
    server              = llGetSimulatorHostname();
 
    currentFPS          = llFloor(llGetRegionFPS());
    totalFPS            += currentFPS;
 
    averageFPS          = totalFPS / numberOfUpdates;
 
    vector color_red = <1.0, 0.0, 0.0>;
    llSetText("Region Performance\n"
              + server + "\n"
              + regionName + "\n"
              + (string)currentFPS + "fps",
              color_red, 1.0);
 
    simStatusReqId      = llRequestSimulatorData(regionName, DATA_SIM_STATUS);
}


send_data(float dil, integer fps)
send_data(float dil, integer fps)
{
{
     //fps = fps - 10; //just for testing!
     postReqId = llHTTPRequest(website, [
    //dil = dilationtime;
                                    HTTP_METHOD, "POST",
url_inform = llHTTPRequest(website,[HTTP_METHOD,"POST",HTTP_MIMETYPE, "application/x-www-form-urlencoded"],"dil="+(string)dil+"&fps="+(string)fps+"&region="+RegName+"&server="+server+"&method=set");
                                    HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
                                "dil=" + (string)dil
                                + "&fps=" + (string)fps
                                + "&region=" + regionName
                                + "&server=" + server
                                + "&method=set");
}
}


default
default
{
{
    on_rez(integer start_param)
    {
        llResetScript();
    }


state_entry()
    changed(integer change)
     {
     {
         RegName = llGetRegionName();
         if (change & CHANGED_REGION)
        server=llGetSimulatorHostname();
            llResetScript();
        Count = 0;
    }
        FPS_Total = 0;


        llSetText("Collecting Performance-Data for \n" + llGetSimulatorHostname() + "\n" + RegName + "...",<1,0,0>,1);
     state_entry()
        llSetTimerEvent(60.0);
    }
   
     on_rez(integer peram)
     {
     {
         llResetScript();
         init();
     }
     }
   
 
     timer()
     timer()
     {
     {
         Count += 1;
         update_data();
        integer RegFPS = llFloor(llGetRegionFPS());
         send_data(currentTimeDilation, currentFPS);
        FPS_Total += RegFPS;
        integer avgFPS = FPS_Total / Count;
        avg = (string)avgFPS;
        RegName = llGetRegionName();
        TimeDil = llGetRegionTimeDilation();
        s_count = (string)Count;
           
        SimStatusQuery = llRequestSimulatorData(RegName, DATA_SIM_STATUS);
       
         send_data((float)TimeDil,(integer)RegFPS);
         //simstatus == "up"/"down"/"starting"/"stopping"/"crashed"/"unknown"
         //simstatus == "up"/"down"/"starting"/"stopping"/"crashed"/"unknown"
     }
     }
Line 78: Line 109:
     http_response(key id, integer status, list meta, string body)
     http_response(key id, integer status, list meta, string body)
     {
     {
        //llSay(0,body);
    // llSay(PUBLIC_CHANNEL, body);
        string result;
         if (id != postReqId)
         if (id==url_inform)
            return;
         {
 
            integer stringpartposition = llSubStringIndex(body,"result = ");
         integer stringpartposition = llSubStringIndex(body, "result = ");
            if(stringpartposition != 0)
        if (stringpartposition == 0)
             {
             return;
                result = llGetSubString(body,stringpartposition + 9,-1);
 
                llStringTrim(result,STRING_TRIM);
        string result = llGetSubString(body, stringpartposition + 9, -1);
           
        llStringTrim(result, STRING_TRIM);
                if (result == "ERROR occured")
 
                {
        if (result != "ERROR occured")
                    llInstantMessage(llGetOwner(),"An error has occured with the Simperformance-Grapher for sim " + RegName + "! Check the rrd and the PHP-Script!");
            return;
                }
 
            }
        key owner = llGetOwner();
        }
        llInstantMessage(owner,
            "An error has occured with the Simperformance-Grapher for sim '"
            + regionName + "'. Check the rrd and the PHP-Script!");
     }
     }


     dataserver(key queryId, string data)  
     dataserver(key query_id, string data)  
        {
    {
            if (queryId == SimStatusQuery) {
        if (query_id != simStatusReqId)
                SimStatusQuery = "";
            return;
                simstatus = (data);
 
            }
        simStatusReqId = "";
        }
        simstatus = (data);
    }
}
}
</lsl>
</lsl>

Revision as of 12:58, 28 July 2013

created by DeniseHoorn Slade

Want to present your Sim on a website with a graph for DIL, FPS and PING? Or do you have some troubles with your sim and problems with LL-support, because they are in opinion, that your sim is running fine? So with these graphs you can show the LL-support the DIL, FPS and PING-times during the last 24 hours!

See examples at the professional service of SL-Simperformance.de

I am sure if other scripter will realize other ideas, we will have at least a very good overview on our sims - PLEEEEASE inform me, if you pimp up this script!

Important

This scripts are under the licence of GPL. You are not allowed to sell any objects using this script.

What you need:

A server elsewhere in the WWW with an installed Apache or IIS. PHP, and rrdtools installed. You need some basic knowledge on PHP-scripting and LSL-scripting. I try to describe the installation as easy as possible.

Introduction

This is the lsl-script. Rezz a box, texture it like a server and place it elsewhere on the sim. No need to be a simowner, no need to deed this prim. This script collects the internal grabable informations: FPS, DIL, servername and simname and sends it via HTTP to a PHP-Script on your website. The PHP-script is below. Attention! Watch, that the path to your php-script is correct!

<lsl> float currentTimeDilation;

integer currentFPS; integer totalFPS; float averageFPS;

integer numberOfUpdates;

string regionName; string server;

string simstatus;

key simStatusReqId; string postReqId;

string website;

init() {

   website = "http://www.yourdomainhere.com/php/write_rrd.php";
   update_data();

// every minute

   llSetTimerEvent(60.0);

}

update_data() { // increment counter...

   ++numberOfUpdates;
   regionName          = llGetRegionName();
   currentTimeDilation = llGetRegionTimeDilation();
   server              = llGetSimulatorHostname();
   currentFPS          = llFloor(llGetRegionFPS());
   totalFPS            += currentFPS;
   averageFPS          = totalFPS / numberOfUpdates;
   vector color_red = <1.0, 0.0, 0.0>;
   llSetText("Region Performance\n"
             + server + "\n"
             + regionName + "\n"
             + (string)currentFPS + "fps",
             color_red, 1.0);
   simStatusReqId      = llRequestSimulatorData(regionName, DATA_SIM_STATUS);

}

send_data(float dil, integer fps) {

   postReqId = llHTTPRequest(website, [
                                   HTTP_METHOD, "POST",
                                   HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
                               "dil=" + (string)dil
                               + "&fps=" + (string)fps
                               + "&region=" + regionName
                               + "&server=" + server
                               + "&method=set");

}

default {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   changed(integer change)
   {
       if (change & CHANGED_REGION)
           llResetScript();
   }
   state_entry()
   {
       init();
   }
   timer()
   {
       update_data();
       send_data(currentTimeDilation, currentFPS);
       //simstatus == "up"/"down"/"starting"/"stopping"/"crashed"/"unknown"
   }
   http_response(key id, integer status, list meta, string body)
   {
   //  llSay(PUBLIC_CHANNEL, body);
       if (id != postReqId)
           return;
       integer stringpartposition = llSubStringIndex(body, "result = ");
       if (stringpartposition == 0)
           return;
       string result = llGetSubString(body, stringpartposition + 9, -1);
       llStringTrim(result, STRING_TRIM);
       if (result != "ERROR occured")
           return;
       key owner = llGetOwner();
       llInstantMessage(owner,
           "An error has occured with the Simperformance-Grapher for sim '"
           + regionName + "'. Check the rrd and the PHP-Script!");
   }
   dataserver(key query_id, string data) 
   {
       if (query_id != simStatusReqId)
           return;
       simStatusReqId = "";
       simstatus = (data);
   }

} </lsl>

On your server lets create the rrd's (Round Robin Databases) --> http://www.mrtg.org/rrdtool/ Here are the commands to create a rrd. Let me first say, that I have very less knowledge on rrd's what I have created is an overview for a day. if somebody is able to make it much much better, PLEASE let me know! IMPORTANT: The synonym "nameofyoursim" has to be replaced exactly with the simname! The php-script get's the simname and adds only a "_dilfps.rrd" so watch

/usr/bin/rrdtool create nameofyoursim_dilfps.rrd --step 600 DS:dil:GAUGE:600:0:1 DS:fps:GAUGE:600:0:50 RRA:AVERAGE:0.5:1:5040 RRA:AVERAGE:0.5:12:9600

The ping-database will be created with:

/usr/bin/rrdtool create NDL_FeEseGrimLa_ping.rrd --step 300 DS:ping:GAUGE:300:0:1 RRA:AVERAGE:0.5:1:5040 RRA:AVERAGE:0.5:12:9600

This is the PHP-script which is called by the lsl-script. It takes the data, pings the server and put all data into the rrd's

<php> <?php

$method = $_POST['method']; $dil = $_POST['dil']; $fps = $_POST['fps']; $region = $_POST['region']; $server = $_POST['server']; $path = "/home/n/ndlsim.de/php/cms/php/";


if ($method=="") {

   die("result = No Method provided!");

}

if ($region=="") {

   die("result = No region provided!");
   //alerts script in SL not to send any data any more and to inform the owner about this damn error... :)

} else {

   $region = str_replace(" ","_",$region);
   $RRDFILE = $path.$region."_dilfps.rrd";
   $RRDFILE_ping = $path.$region."_ping.rrd";

}

echo ("result = $server"); $resultping = shell_exec("/bin/ping $server -c 1"); $var1 = strpos($resultping, "time="); $ping = trim((substr($resultping,$var1+5,3)));


if ($method=="set") {

   //write data into rrd's
   $ret = exec("/usr/bin/rrdtool update $RRDFILE -t dil:fps N:$dil:$fps");
       if( $ret1 != 0 )
       {
           die ("result = ERROR occurred");
       }

// echo "result = /usr/bin/rrdtool update $RRDFILE -t dil:fps N:$dil:$fps";

   $ret = exec("/usr/bin/rrdtool update $RRDFILE_ping -t ping N:$ping");
       if( $ret2 != 0 )
       {
           die ("result = ERROR occurred");
       }

// echo ("result = /usr/bin/rrdtool update $RRDFILE_ping -t ping N:$ping"); //echo ("result = $ping");

} ?> </php>

And last but not least, we have to build the graph from the data. it's a bash-script (Linux) which create the graphs.

<php>

  1. !/bin/bash

RRDFILE=/home/n/ndlsim.de/php/cms/php/yoursimnamehere_dilfps.rrd RRDPING=/home/n/ndlsim.de/php/cms/php/yoursimnamehere_ping.rrd

GRAPHFILE1=/home/n/ndlsim.de/php/cms/bilder/yoursimname_DIL.png GRAPHFILE2=/home/n/ndlsim.de/php/cms/bilder/yoursimname_FPS.png GRAPHFILE3=/home/n/ndlsim.de/php/cms/bilder/yoursimname_ping.png

rrdtool graph $GRAPHFILE1 -v "Dilation" \

 -u 1.1 -l 0 \
 -t "Dilation Time for yoursim" \
 DEF:dil=$RRDFILE:dil:AVERAGE LINE2:dil#309030:"Dilation Time" \
 HRULE:1.0#AAAA00:"Performace best / Performance sehr gut" \
 HRULE:0.8#0000FF:"Performace ok / Performance gut" \
 HRULE:0.5#FF0000:"Lagging expected / Lag zu erwarten" \
 COMMENT:"\\n" \
 COMMENT:"(Last updated\: $(/bin/date "+%d.%m.%Y %H\:%M\:%S"))\r" \
 -w 600 -h 200 -a PNG

rrdtool graph $GRAPHFILE2 -v "FPS" \

 -u 50.0 -l 0 \
 -t "Frames Per Second for yoursim" \
 DEF:fps=$RRDFILE:fps:AVERAGE LINE2:fps#309030:"Frames Per Second" \
 HRULE:44#AAAA00:"Performace best / Performance sehr gut" \
 HRULE:35#0000FF:"Performance ok /Performance gut" \
 HRULE:20#FF0000:"Lagging / Lag" \
 HRULE:10#FF0000:"Terrible / Katastrophal" \
 COMMENT:"\\n" \
 COMMENT:"(Last updated\: $(/bin/date "+%d.%m.%Y %H\:%M\:%S"))\r" \
 -w 600 -h 200 -a PNG

rrdtool graph $GRAPHFILE3 -v "PING-Time" \

 -u 200.0 -l 60 \
 -t "PING-Time for yoursim" \
 DEF:ping=$RRDPING:ping:AVERAGE LINE2:ping#309030:"PING in ms" \
 HRULE:90#AAAA00:"Performace best / Performance sehr gut" \
 HRULE:140#0000FF:"Performance ok /Performance gut" \
 HRULE:190#FF0000:"Lagging / Lag" \
 COMMENT:"\\n" \
 COMMENT:"(Last updated\: $(/bin/date "+%d.%m.%Y %H\:%M\:%S"))\r" \
 -w 600 -h 200 -a PNG

</php>

Hope you will find it useful. If so, drop me a note inworld...