Test Page

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Useful Stuff)
(JSON Grid Simstats)
Line 266: Line 266:
 
  import urllib2
 
  import urllib2
  
  ''' From regions.regionSecret '''
+
  ''' value shown is an example, get this from your grid database each time - regions.regionSecret '''
 
  regionsecret = 'fe21314b-6267-44f7-aa1e-6047e1c3f94a'
 
  regionsecret = 'fe21314b-6267-44f7-aa1e-6047e1c3f94a'
  
Line 283: Line 283:
 
  regiondata = simplejson.load(urllib2.urlopen(regionuri))
 
  regiondata = simplejson.load(urllib2.urlopen(regionuri))
  
  ''' OSStatsURI is the uri to query the OpenSim instance. retrun ssame data as the user set uri '''
+
  ''' OSStatsURI is the uri to query the OpenSim instance. return same data as the user set uri '''
 
  simuri = regiondata['OSStatsURI']
 
  simuri = regiondata['OSStatsURI']
  

Revision as of 11:31, 19 January 2011

Contents

Useful Scripts

This is a small script to watch for an OpenSim region simulator under screen in Linux. If the process is missing, a new instance will be started.

oswatchdog

#!/bin/sh
 #
 # THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 # DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 #
 #
 # Adjust To Your System:
 #
 # Sample Cron Entry: Runs Each Minute 24/7/365
 # */1 * * * * exec /opt/opensim/scripts/oswatchdog
 #
 #
 #
 # Where Does Your OpenSim Installation Live?
 BASE="/opt/opensim"
 # Where Do You Run OpenSim.exe From?
 RUN="$BASE/production/bin"
 # Where Do You Want To Log Events To?
 LOG="$BASE/log"
 # Where Is Your Screen Binary?
 SCREEN="/usr/bin/screen"
 # What is your hostname where your region lives?
 HOSTNAME="myregion.server.com"
 # What is the port you listen to? The default is 9000 
 PORT="9000"
 
 #if the file exist, opensim wont be restarted
 # Sacha Magne
 LOCKFILE="/tmp/norun.opensim"
 
 if [ -f "$LOCKFILE" ]; then
   echo $LOCKFILE "found. no restart"
   exit
 fi
 
 
 # Check For For Our Screen Process, Named OSG
 running=`ps ax|grep OSG|grep -v grep`|tr -s ' '|sed 's/^ //'|cut -f1 -d' '
 
 # If The Process Is Not There...
 if [ -z "$running" ]; then
 				#...We Make A Log Entry And Start A New One
 	# The Log Entry
 	TIME="Simulator Down, Restarting: `/usr/bin/date +"%A, %B %d - %r"`"
 
 	echo $TIME >>$LOG/OSGReport.txt
 	cd $RUN
 	$SCREEN -S OSG -d -m mono OpenSim.exe
 else
        if curl "http://$HOSTNAME:$PORT/simstatus/"
        then
              exit 0
        else
              kill -KILL $running
        fi
 fi
 # All Done Till Next Time

Starting and stopping the grid server via script

#!/bin/bash
 #
 #
 OSDIR=/opt/OpenSim
 OSRUNDIR=lib/opensim/trunk/bin
 export SCREENDIR=$OSDIR/var/run/screen
 
 case "$1" in
 
	'start')
		echo "Starting Grid Services"
 
		for i in BWG
		do 
			kill `ls $SCREENDIR/*.$i |
		 	cut -d'/' -f7  |
		 	sed s/[^0-9]//g`
		done
		screen -wipe
		sleep 3
 
		cd  $OSDIR/$OSRUNDIR
 
	echo "User Server..."
		screen -dmS BWG -t US mono OpenSim.Grid.UserServer.exe &
		screen -S BWG -X hardstatus alwayslastline "%{=b}%{G} %H Screen(s): %{b}%w %=%{kG}%C%A  %D, %M/%d/%Y "
		sleep 5
		echo "Grid Server..."
		screen -S BWG -X screen -t GS mono OpenSim.Grid.GridServer.exe &
		sleep 5
		echo "Asset Server..."
		screen -S BWG -X screen -t AS mono OpenSim.Grid.AssetServer.exe &
		sleep 5
		echo "Inventory Server..."
		screen -S BWG -X screen -t IS mono OpenSim.Grid.InventoryServer.exe &
		echo "Messaging Server..."
		screen -S BWG -X screen -t MS mono OpenSim.Grid.MessagingServer.exe &
	;;
 
	'stop')
		for i in BWG
		do 
			kill `ls $SCREENDIR/*.$i |
		 	cut -d'/' -f7  |
		 	sed s/[^0-9]//g`
		done
		screen -wipe
	;;
 
	'screen')
		screen -r BWG
	;;
 
 esac

JSON User SimStats

As of OpenSim svn 9529 the xtended stats reporting will return a jsonp callback to allow popular javascript toolkits to use the returned data to create ajax monitoring applications in the browser. This is an advantage because after the page is loaded, the browser will interact directly with the region, eliminating traffic through the website (polling the region and servicing the browser). It also allows the creation of mashups to create mini-monitor apps in other pages.

To enable your stats reporting, set the following in your OpenSim.ini...

   ; Simulator Stats URI
   ; Enable JSON simulator data by setting a URI name (case sensitive)
   Stats_URI = "jsonSimStats"

...the URI can be anything you want, and is case sensitive. You can query the URI directly to return a json string to use in php, python, java, etc. or you may use one of the popular javascript toolkits to have OpenSim generate a callback for jsonp. The json serialization carries the following data...

 {"AssetsInCache":5.0,"TimeAfterCacheMiss":0.0,"BlockedMissingTextureRequests":0.0,"AssetServiceRequestFailures":0.0,
"abnormalClientThreadTerminations":0.0,"InventoryServiceRetrievalFailures":0.0,"Dilatn":0.967380821704865,"SimFPS":55.0,
"PhyFPS":47.1628913879395,"AgntUp":0.0,"RootAg":0.0,"ChldAg":0.0,"Prims":0.0,"AtvPrm":0.0,"AtvScr":0.0,"ScrLPS":0.0,
"PktsIn":0.0,"PktOut":0.0,"PendDl":0.0,"PendUl":0.0,"UnackB":0.0,"TotlFt":0.0,"NetFt":0.0,"PhysFt":0.0,"OthrFt":0.0,
"AgntFt":0.0,"ImgsFt":0.0,"Memory":"8","Uptime":"05:12:19.0365590","Version":"OpenSimulator Server  0.6.4.9533 "}


<html>
 <head>
    <title>JSON Test</title>
 <script src="http://ascent.bluewallgroup.com/jquery-1.3.2.js"></script>
 <script src="http://ascent.bluewallgroup.com/timer.js"></script>
 <script type="text/javascript" src="http://www.google.com/jsapi"></script>
 <script type="text/javascript" language="JavaScript">
  SimFPS = 0;
  PhyFPS = 0;
  Memory = 0;
  RootAg = 0;
  ChldAg = 0;
  Uptime = "";
  Version = "";
 </script>
 
 
 <script type="text/javascript" language="JavaScript">
 
 
  $.timer(15000, function(timer) {
  $.getJSON("http://ascent.bluewallgroup.com:9300/jsonSimStats/?callback=?",
 
  function(data){
 
      SimFPS = Math.round(data.SimFPS);
      PhyFPS = Math.round(data.PhyFPS);
      Memory = Math.round(data.Memory);
      ChldAg = data.ChldAg;
      RootAg = data.RootAg;
      Uptime = data.Uptime;
      Version = data.Version;
      drawChart();
      setTags();
      timer.reset(15000);
  });
  });
 </script>
 
 <script type="text/javascript" language="JavaScript">
 
  google.load("visualization", "1", {packages:["gauge"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var cdata = new google.visualization.DataTable();
    cdata.addColumn('string', 'Label');
    cdata.addColumn('number', 'Value');
    cdata.addRows(3);
    cdata.setValue(0, 0, 'SimFPS');
    cdata.setValue(0, 1, SimFPS);
    cdata.setValue(1, 0, 'PhyFPS');
    cdata.setValue(1, 1, PhyFPS);
    cdata.setValue(2, 0, 'Memory');
    cdata.setValue(2, 1, Memory);
 
    var chart = new
 google.visualization.Gauge(document.getElementById('chart_div'));
    var options = {width: 400, height: 120, redFrom: 90, redTo: 100,
        yellowFrom:75, yellowTo: 90, minorTicks: 5};
    chart.draw(cdata, options);
  }
 </script>
 
 <script type="text/javascript" language="JavaScript">
   function setTags() {
      $("#par-uptime").text("Uptime: "  + Uptime);
      $("#par-ragent").text("Root Agent: " + RootAg);
      $("#par-version").text("Version: " + Version);
      $("#par-cagent").text("Child Agent: " + ChldAg);
   }
 </script>
 
 </head>
 <body>
 <h1>BlueWall Development Region</h1>
 <table>
 <tr><td>
 <div id="par-version">version</div>
 </td><td>
 <div id="par-ragent">root agent</div>
 </td></tr><tr><td>
 <div id="par-uptime">uptime</div>
 </td><td>
 <div id="par-cagent">child agent</div>
 </td></tr>
 </table>
 <div id="chart_div"></div>
 </body>
 </html>

JSON Grid Simstats

Python example to gain the region data from a grid service

- should work but this version not tested -
        *reference material* 
import hashlib
 import urllib2
 
 ''' value shown is an example, get this from your grid database each time - regions.regionSecret '''
 regionsecret = 'fe21314b-6267-44f7-aa1e-6047e1c3f94a'
 
 ''' My region host '''
 hostName =  myregion.host.net
 
 ''' My region port '''
 hostPort = 9000
 
 ''' create an *UPPERCASE* SHA1 hash from the regionSecret '''
 resourceName = str(hashlib.sha1(regionsecret).hexdigest()).upper()
 
 regionuri = hostName + ":" + hostPort + "/" + resourceName + "/"
 
 ''' data includes TimeZoneName , TimeZoneOffs, UxTime, Memory, Version and OSStatsURI '''
 regiondata = simplejson.load(urllib2.urlopen(regionuri))
 
 ''' OSStatsURI is the uri to query the OpenSim instance. return same data as the user set uri '''
 simuri = regiondata['OSStatsURI']
 
 simdata = simplejson.load(urllib2.urlopen(simuri))
Personal tools
General
About This Wiki