aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/UserStatistics/WebStatsModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/UserStatistics/WebStatsModule.cs')
-rw-r--r--OpenSim/Region/UserStatistics/WebStatsModule.cs72
1 files changed, 56 insertions, 16 deletions
diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs
index b08233c..b98b762 100644
--- a/OpenSim/Region/UserStatistics/WebStatsModule.cs
+++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs
@@ -94,8 +94,6 @@ namespace OpenSim.Region.UserStatistics
94 if (!enabled) 94 if (!enabled)
95 return; 95 return;
96 96
97 AddEventHandlers();
98
99 if (Util.IsWindows()) 97 if (Util.IsWindows())
100 Util.LoadArchSpecificWindowsDll("sqlite3.dll"); 98 Util.LoadArchSpecificWindowsDll("sqlite3.dll");
101 99
@@ -123,6 +121,10 @@ namespace OpenSim.Region.UserStatistics
123 reports.Add("clients.report", clientReport); 121 reports.Add("clients.report", clientReport);
124 reports.Add("sessions.report", sessionsReport); 122 reports.Add("sessions.report", sessionsReport);
125 123
124 reports.Add("sim.css", new Prototype_distributor("sim.css"));
125 reports.Add("sim.html", new Prototype_distributor("sim.html"));
126 reports.Add("jquery.js", new Prototype_distributor("jquery.js"));
127
126 //// 128 ////
127 // Add Your own Reports here (Do Not Modify Lines here Devs!) 129 // Add Your own Reports here (Do Not Modify Lines here Devs!)
128 //// 130 ////
@@ -143,10 +145,14 @@ namespace OpenSim.Region.UserStatistics
143 lock (m_scenes) 145 lock (m_scenes)
144 { 146 {
145 m_scenes.Add(scene); 147 m_scenes.Add(scene);
146 if (m_simstatsCounters.ContainsKey(scene.RegionInfo.RegionID)) 148 updateLogMod = m_scenes.Count * 2;
147 m_simstatsCounters.Remove(scene.RegionInfo.RegionID);
148 149
149 m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID)); 150 m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID));
151
152 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
153 scene.EventManager.OnDeregisterCaps += OnDeRegisterCaps;
154 scene.EventManager.OnClientClosed += OnClientClosed;
155 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
150 scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket; 156 scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket;
151 } 157 }
152 } 158 }
@@ -157,6 +163,15 @@ namespace OpenSim.Region.UserStatistics
157 163
158 public void RemoveRegion(Scene scene) 164 public void RemoveRegion(Scene scene)
159 { 165 {
166 if (!enabled)
167 return;
168
169 lock (m_scenes)
170 {
171 m_scenes.Remove(scene);
172 updateLogMod = m_scenes.Count * 2;
173 m_simstatsCounters.Remove(scene.RegionInfo.RegionID);
174 }
160 } 175 }
161 176
162 public virtual void Close() 177 public virtual void Close()
@@ -187,9 +202,7 @@ namespace OpenSim.Region.UserStatistics
187 private void ReceiveClassicSimStatsPacket(SimStats stats) 202 private void ReceiveClassicSimStatsPacket(SimStats stats)
188 { 203 {
189 if (!enabled) 204 if (!enabled)
190 {
191 return; 205 return;
192 }
193 206
194 try 207 try
195 { 208 {
@@ -198,17 +211,25 @@ namespace OpenSim.Region.UserStatistics
198 if (concurrencyCounter > 0 || System.Environment.TickCount - lastHit > 30000) 211 if (concurrencyCounter > 0 || System.Environment.TickCount - lastHit > 30000)
199 return; 212 return;
200 213
201 if ((updateLogCounter++ % updateLogMod) == 0) 214 // We will conduct this under lock so that fields such as updateLogCounter do not potentially get
215 // confused if a scene is removed.
216 // XXX: Possibly the scope of this lock could be reduced though it's not critical.
217 lock (m_scenes)
202 { 218 {
203 m_loglines = readLogLines(10); 219 if (updateLogMod != 0 && updateLogCounter++ % updateLogMod == 0)
204 if (updateLogCounter > 10000) updateLogCounter = 1; 220 {
205 } 221 m_loglines = readLogLines(10);
222
223 if (updateLogCounter > 10000)
224 updateLogCounter = 1;
225 }
206 226
207 USimStatsData ss = m_simstatsCounters[stats.RegionUUID]; 227 USimStatsData ss = m_simstatsCounters[stats.RegionUUID];
208 228
209 if ((++ss.StatsCounter % updateStatsMod) == 0) 229 if ((++ss.StatsCounter % updateStatsMod) == 0)
210 { 230 {
211 ss.ConsumeSimStats(stats); 231 ss.ConsumeSimStats(stats);
232 }
212 } 233 }
213 } 234 }
214 catch (KeyNotFoundException) 235 catch (KeyNotFoundException)
@@ -238,9 +259,12 @@ namespace OpenSim.Region.UserStatistics
238 string regpath = request["uri"].ToString(); 259 string regpath = request["uri"].ToString();
239 int response_code = 404; 260 int response_code = 404;
240 string contenttype = "text/html"; 261 string contenttype = "text/html";
262 bool jsonFormatOutput = false;
241 263
242 string strOut = string.Empty; 264 string strOut = string.Empty;
243 265
266 // The request patch should be "/SStats/reportName" where 'reportName'
267 // is one of the names added to the 'reports' hashmap.
244 regpath = regpath.Remove(0, 8); 268 regpath = regpath.Remove(0, 8);
245 if (regpath.Length == 0) regpath = "default.report"; 269 if (regpath.Length == 0) regpath = "default.report";
246 if (reports.ContainsKey(regpath)) 270 if (reports.ContainsKey(regpath))
@@ -248,6 +272,9 @@ namespace OpenSim.Region.UserStatistics
248 IStatsController rep = reports[regpath]; 272 IStatsController rep = reports[regpath];
249 Hashtable repParams = new Hashtable(); 273 Hashtable repParams = new Hashtable();
250 274
275 if (request.ContainsKey("json"))
276 jsonFormatOutput = true;
277
251 if (request.ContainsKey("requestvars")) 278 if (request.ContainsKey("requestvars"))
252 repParams["RequestVars"] = request["requestvars"]; 279 repParams["RequestVars"] = request["requestvars"];
253 else 280 else
@@ -267,13 +294,26 @@ namespace OpenSim.Region.UserStatistics
267 294
268 concurrencyCounter++; 295 concurrencyCounter++;
269 296
270 strOut = rep.RenderView(rep.ProcessModel(repParams)); 297 if (jsonFormatOutput)
298 {
299 strOut = rep.RenderJson(rep.ProcessModel(repParams));
300 contenttype = "text/json";
301 }
302 else
303 {
304 strOut = rep.RenderView(rep.ProcessModel(repParams));
305 }
271 306
272 if (regpath.EndsWith("js")) 307 if (regpath.EndsWith("js"))
273 { 308 {
274 contenttype = "text/javascript"; 309 contenttype = "text/javascript";
275 } 310 }
276 311
312 if (regpath.EndsWith("css"))
313 {
314 contenttype = "text/css";
315 }
316
277 concurrencyCounter--; 317 concurrencyCounter--;
278 318
279 response_code = 200; 319 response_code = 200;
@@ -380,7 +420,7 @@ namespace OpenSim.Region.UserStatistics
380 Encoding encoding = Encoding.ASCII; 420 Encoding encoding = Encoding.ASCII;
381 int sizeOfChar = encoding.GetByteCount("\n"); 421 int sizeOfChar = encoding.GetByteCount("\n");
382 byte[] buffer = encoding.GetBytes("\n"); 422 byte[] buffer = encoding.GetBytes("\n");
383 string logfile = Util.logDir() + "/" + "OpenSim.log"; 423 string logfile = Util.logFile();
384 FileStream fs = new FileStream(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 424 FileStream fs = new FileStream(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
385 Int64 tokenCount = 0; 425 Int64 tokenCount = 0;
386 Int64 endPosition = fs.Length / sizeOfChar; 426 Int64 endPosition = fs.Length / sizeOfChar;