Test Page

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(oswatchdog)
(JSON User SimStats)
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Useful Stuff=
+
'''As of 2011-10-10 I copy/pasted this over to the linked [[UXSimStatus]] for further change/editing -- [[User:Justincc|Justincc]] 20:22, 10 October 2011 (UTC)'''
  
==Sunrise/Sunset Table==
 
This seems to always change, but here is a set of lsl lists with the current sunrise/sunset times in GMT
 
<source lang="lsl">
 
list SunRise = [5400.0,19800.0,34200.0,48600.0,63000.0,77400.0];
 
list SunSet = [1800.0,16200.0,30600.0,45000.0,59400.0,73800.0];
 
</source>
 
  
==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==
 
  
<source lang="bash">
+
 
#!/bin/sh
+
== JSON User SimStats ==
#
+
 
# THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+
As of OpenSim svn 9529 the xtended stats reporting will return a jsonp
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
callback to allow popular javascript toolkits to use the returned data to
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
create ajax monitoring applications in the browser. This is an advantage
# DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+
because after the page is loaded, the browser will interact directly with
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
the region, eliminating traffic through the website (polling the region and
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
servicing the browser). It also allows the creation of mashups to create
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
mini-monitor apps in other pages.
  # 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
+
To enable your stats reporting, set the following in your OpenSim.ini...
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 
  #
+
    ; Simulator Stats URI
#
+
    ; Enable JSON simulator data by setting a URI name (case sensitive)
#
+
    Stats_URI = "jsonSimStats"
  # Adjust To Your System:
+
 
#
+
...the URI can be anything you want, and is case sensitive. You can query
# Sample Cron Entry: Runs Each Minute 24/7/365
+
the URI directly to return a json string to use in php, python, java, etc.
# */1 * * * * exec /opt/opensim/scripts/oswatchdog
+
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...
#
+
 
# Where Does Your OpenSim Installation Live?
+
  {"AssetsInCache":5.0,"TimeAfterCacheMiss":0.0,"BlockedMissingTextureRequests":0.0,"AssetServiceRequestFailures":0.0,
BASE="/opt/opensim"
+
  "abnormalClientThreadTerminations":0.0,"InventoryServiceRetrievalFailures":0.0,"Dilatn":0.967380821704865,"SimFPS":55.0,
# Where Do You Run OpenSim.exe From?
+
  "PhyFPS":47.1628913879395,"AgntUp":0.0,"RootAg":0.0,"ChldAg":0.0,"Prims":0.0,"AtvPrm":0.0,"AtvScr":0.0,"ScrLPS":0.0,
RUN="$BASE/production/bin"
+
  "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,
# Where Do You Want To Log Events To?
+
  "AgntFt":0.0,"ImgsFt":0.0,"Memory":"8","Uptime":"05:12:19.0365590","Version":"OpenSimulator Server 0.6.4.9533 "}
LOG="$BASE/log"
+
 
# Where Is Your Screen Binary?
+
 
SCREEN="/usr/bin/screen"
+
  <source lang="html4strict">
  # What is your hostname where your region lives?
+
 
HOSTNAME="myregion.server.com"
+
<!DOCTYPE HTML>
# What is the port you listen to? The default is 9000
+
<html>
PORT="9000"
+
<head>
+
<title>JSON Test</title>
#if the file exist, opensim wont be restarted
+
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
# Sacha Magne
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
LOCKFILE="/tmp/norun.opensim"
+
<script type="text/javascript" language="JavaScript">
+
 
if [ -f "$LOCKFILE" ]; then
+
SimFPS = 0;
  echo $LOCKFILE "found. no restart"
+
PhyFPS = 0;
  exit
+
Memory = 0;
fi
+
RootAg = 0;
+
ChldAg = 0;
+
Uptime = "";
# Check For For Our Screen Process, Named OSG
+
Version = "";
running=`ps ax|grep OSG|grep -v grep`|tr -s ' '|sed 's/^ //'|cut -f1 -d' '
+
 
+
setInterval(function(){
# If The Process Is Not There...
+
$.getJSON(
if [ -z "$running" ]; then
+
  "http://ascent.bluewallgroup.com:9100/jsonSimStats/?callback=?",  
#...We Make A Log Entry And Start A New One
+
  function(data){
# The Log Entry
+
  SimFPS = Math.round(data.SimFPS);
TIME="Simulator Down, Restarting: `/usr/bin/date +"%A, %B %d - %r"`"
+
  PhyFPS = Math.round(data.PhyFPS);
   
+
  Memory = Math.round(data.Memory);
echo $TIME >>$LOG/OSGReport.txt
+
  ChldAg = data.ChldAg;
cd $RUN
+
  RootAg = data.RootAg;
$SCREEN -S OSG -d -m mono OpenSim.exe
+
  Uptime = data.Uptime;
else
+
  Version = data.Version;
        if curl "http://$HOSTNAME:$PORT/simstatus/"
+
  drawChart();
        then
+
  setTags();
              exit 0
+
  })}, 3000
        else
+
);
              kill -KILL $running
+
 
        fi
+
 
fi
+
google.load("visualization", "1", {packages:["gauge"]});
# All Done Till Next Time
+
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);
 +
}
 +
 
 +
$(function() {
 +
    timer.start(100);
 +
    });
 +
 
 +
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>
 +
= BlueWall Development Region =
 +
<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>
 +
 
 
  </source>
 
  </source>
 
-----------------------------------------------------------------------------------------------------------------
 
  
== Starting and stopping the grid server via script ==
+
[[SSL in OpenSim]]
  <source lang="bash">  
+
 
  #!/bin/sh
+
== JSON Grid Simstats ==
  #
+
 
  # where does your OpenSim live?
+
Python example to gain the region data from a grid service
  export OSDIR=/opt/opensim/OSDev/production/bin
+
  - should work but this version not tested -
+
        *reference material*
  case $1 in
+
 
+
  <source lang="python">
'start')
+
 
   
+
  import hashlib
cd $OSDIR
+
  import urllib2
screen -dmS US mono OpenSim.Grid.UserServer.exe
+
 
sleep 3
+
  ''' value shown is an example, get this from your grid database each time - regions.regionSecret '''
screen -dmS GS mono OpenSim.Grid.GridServer.exe
+
  regionsecret = 'fe21314b-6267-44f7-aa1e-6047e1c3f94a'
sleep 3
+
 
screen -dmS IS mono OpenSim.Grid.InventoryServer.exe
+
  ''' My region host '''
sleep 3
+
  hostName =  myregion.host.net
screen -dmS AS mono OpenSim.Grid.AssetServer.exe
+
 
sleep 3
+
''' My region port '''
screen -dmS MS mono OpenSim.Grid.MessagingServer.exe
+
hostPort = 9000
   
+
 
        # you can start your regions too, if you like
+
''' create an *UPPERCASE* SHA1 hash from the regionSecret '''
#sleep 45
+
resourceName = str(hashlib.sha1(regionsecret).hexdigest()).upper()
#screen -dmS BWV mono OpenSim.exe
+
 
   
+
  regionuri = hostName + ":" + hostPort + "/" + resourceName + "/"
;;
+
 
 
+
''' data includes TimeZoneName , TimeZoneOffs, UxTime, Memory, Version and OSStatsURI '''
'stop')
+
regiondata = simplejson.load(urllib2.urlopen(regionuri))
   
+
 
screen -wipe
+
''' OSStatsURI is the uri to query the OpenSim instance. return same data as the user set uri '''
   
+
  simuri = regiondata['OSStatsURI']
for i in MS IS AS GS US
+
 
do
+
  simdata = simplejson.load(urllib2.urlopen(simuri))
                # you will have to look in the /tmp/screens directory for your username
+
 
                # change whoami to whatever it needs to be
+
  </source>
kill `ls /tmp/screens/S-whoami/*.$i |
+
 
cut -d'/' -f5  |
+
== Using shell environment variables in OpenSim configuration ==
sed s/[^0-9]//g`
+
 
done
+
We will need to use two new things in our configurations: a section [Environment] to tell us what variables we need to look at in the shell and we will need to use the Nini key expansion. Nini, can have keys that look like ${SECTION|VARIABLE} and can expand those to the variables we assign.
+
 
screen -wipe
+
In your shell you will export your values and check the ones you want to use that are predefined by your system ...
+
 
;;
+
<source lang="bash">
+
export RT_ZONE=Zone_00
  esac
+
 
</source>
 
</source>
 +
 +
<source lang="bash">
 +
# You can see your HOSTNAME (It will be set by the system)...
 +
echo $HOSTNAME
 +
OSERV_00
 +
</source>
 +
 +
In the ini you will include an [Environment] section...
 +
<source lang="ini">
 +
[Environment]  ; Our Environment section that defines the shell variables we are interested in
 +
RT_ZONE=""    ; We might use a zone to setup an instance of OpenSim on a server 
 +
HOSTNAME="" ; We might be interested in obtaining the host's name
 +
 +
[Startup]
 +
regionload_regionsdir=/home/opensim/etc/Regions/${Environment|RT_ZONE}/  ; We set our regionload_regionsdir using the variables
 +
ConsolePrompt = "${Environment|HOSTNAME}:${Environment|RT_ZONE} "
 +
 +
[DatabaseService]
 +
ConnectionString = "Data Source=localhost;Database=${Environment|RT_ZONE};User ID=username;Password=userpass;" ; Here too
 +
</source>
 +
 +
 +
 +
When OpenSim picks up the variables in your shell and processes all the configurations, the variable keys will be filled in with the variables picked up from the shell ...
 +
<source lang="ini">
 +
[Environment]  ; Our Environment section that defines the shell variables we are interested in
 +
RT_ZONE=""    ; We might use a zone to setup an instance of OpenSim on a server 
 +
HOSTNAME="" ; We might be interested in obtaining the host's name
 +
 +
[Startup]
 +
regionload_regionsdir=/home/opensim/etc/Regions/Zone_00/  ; We set our regionload_regionsdir using the variables
 +
ConsolePrompt = "OSERV_00:Zone_09 "
 +
 +
[DatabaseService]
 +
ConnectionString = "Data Source=localhost;Database=Zone_00;User ID=username;Password=userpass;" ; Here too
 +
</source>
 +
 +
 +
 +
This is a pretty good start. I think there will be a couple of places we might be able to use this to help us setup really flexible configuration systems for OpenSim.
 +
 +
Have Fun!
 +
 +
== TESTING ==
 +
 +
This is a test

Latest revision as of 17:17, 1 January 2015

As of 2011-10-10 I copy/pasted this over to the linked UXSimStatus for further change/editing -- Justincc 20:22, 10 October 2011 (UTC)



Contents

[edit] 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 "}


<!DOCTYPE HTML>
<html>
<head>
<title>JSON Test</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.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 = "";
 
setInterval(function(){
$.getJSON(
  "http://ascent.bluewallgroup.com:9100/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();
  })}, 3000
);
 
 
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);
}
 
$(function() {
    timer.start(100);
    });
 
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>
= BlueWall Development Region =
<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>

SSL in OpenSim

[edit] 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))

[edit] Using shell environment variables in OpenSim configuration

We will need to use two new things in our configurations: a section [Environment] to tell us what variables we need to look at in the shell and we will need to use the Nini key expansion. Nini, can have keys that look like ${SECTION|VARIABLE} and can expand those to the variables we assign.

In your shell you will export your values and check the ones you want to use that are predefined by your system ...

export RT_ZONE=Zone_00
# You can see your HOSTNAME (It will be set by the system)...
echo $HOSTNAME
OSERV_00

In the ini you will include an [Environment] section...

[Environment]  ; Our Environment section that defines the shell variables we are interested in
RT_ZONE=""     ; We might use a zone to setup an instance of OpenSim on a server  
HOSTNAME="" ; We might be interested in obtaining the host's name 
 
[Startup]
regionload_regionsdir=/home/opensim/etc/Regions/${Environment|RT_ZONE}/   ; We set our regionload_regionsdir using the variables
ConsolePrompt = "${Environment|HOSTNAME}:${Environment|RT_ZONE} "
 
[DatabaseService]
ConnectionString = "Data Source=localhost;Database=${Environment|RT_ZONE};User ID=username;Password=userpass;" ; Here too


When OpenSim picks up the variables in your shell and processes all the configurations, the variable keys will be filled in with the variables picked up from the shell ...

[Environment]  ; Our Environment section that defines the shell variables we are interested in
RT_ZONE=""     ; We might use a zone to setup an instance of OpenSim on a server  
HOSTNAME="" ; We might be interested in obtaining the host's name 
 
[Startup]
regionload_regionsdir=/home/opensim/etc/Regions/Zone_00/   ; We set our regionload_regionsdir using the variables
ConsolePrompt = "OSERV_00:Zone_09 "
 
[DatabaseService]
ConnectionString = "Data Source=localhost;Database=Zone_00;User ID=username;Password=userpass;" ; Here too


This is a pretty good start. I think there will be a couple of places we might be able to use this to help us setup really flexible configuration systems for OpenSim.

Have Fun!

[edit] TESTING

This is a test

Personal tools
General
About This Wiki