29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Monitoring;
37 using OpenSim.Framework.Servers;
38 using OpenSim.Region.CoreModules.Framework.Monitoring.Alerts;
39 using OpenSim.Region.CoreModules.Framework.Monitoring.Monitors;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
44 namespace OpenSim.
Region.CoreModules.Framework.Monitoring
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"MonitorModule")]
52 public bool Enabled {
get;
private set; }
54 private Scene m_scene;
63 private readonly List<IMonitor> m_staticMonitors =
new List<IMonitor>();
65 private readonly List<IAlert> m_alerts =
new List<IAlert>();
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
73 #region Implementation of INonSharedRegionModule
77 IConfig cnfg = source.Configs[
"Monitoring"];
80 Enabled = cnfg.GetBoolean(
"Enabled",
true);
94 m_scene.AddCommand(
"General",
this,
"monitor report",
96 "Returns a variety of statistics about the current region and/or simulator",
99 MainServer.Instance.AddHTTPHandler(
"/monitorstats/" + m_scene.RegionInfo.RegionID, StatsPage);
100 MainServer.Instance.AddHTTPHandler(
101 "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName), StatsPage);
104 RegisterStatsManagerRegionStatistics();
112 MainServer.Instance.RemoveHTTPHandler(
"GET",
"/monitorstats/" + m_scene.RegionInfo.RegionID);
113 MainServer.Instance.RemoveHTTPHandler(
"GET",
"/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName));
115 UnRegisterStatsManagerRegionStatistics();
126 get {
return "Region Health Monitoring Module"; }
133 public Type ReplaceableInterface
155 m_staticMonitors.Add(
158 "TimeDilationMonitor",
160 m => m.Scene.StatsReporter.LastReportedSimStats[0],
161 m => m.GetValue().ToString()));
163 m_staticMonitors.Add(
168 m => m.Scene.StatsReporter.LastReportedSimStats[1],
169 m =>
string.Format(
"{0}", m.GetValue())));
171 m_staticMonitors.Add(
176 m => m.Scene.StatsReporter.LastReportedSimStats[2],
177 m =>
string.Format(
"{0}", m.GetValue())));
179 m_staticMonitors.Add(
182 "AgentUpdatesPerSecondMonitor",
184 m => m.Scene.StatsReporter.LastReportedSimStats[3],
185 m =>
string.Format(
"{0} per second", m.GetValue())));
187 m_staticMonitors.Add(
190 "ActiveObjectCountMonitor",
192 m => m.Scene.StatsReporter.LastReportedSimStats[7],
193 m =>
string.Format(
"{0}", m.GetValue())));
195 m_staticMonitors.Add(
198 "ActiveScriptsMonitor",
200 m => m.Scene.StatsReporter.LastReportedSimStats[19],
201 m =>
string.Format(
"{0}", m.GetValue())));
203 m_staticMonitors.Add(
206 "ScriptEventsPerSecondMonitor",
208 m => m.Scene.StatsReporter.LastReportedSimStats[23],
209 m =>
string.Format(
"{0} per second", m.GetValue())));
211 m_staticMonitors.Add(
214 "InPacketsPerSecondMonitor",
216 m => m.Scene.StatsReporter.LastReportedSimStats[13],
217 m =>
string.Format(
"{0} per second", m.GetValue())));
219 m_staticMonitors.Add(
222 "OutPacketsPerSecondMonitor",
224 m => m.Scene.StatsReporter.LastReportedSimStats[14],
225 m =>
string.Format(
"{0} per second", m.GetValue())));
227 m_staticMonitors.Add(
230 "UnackedBytesMonitor",
232 m => m.Scene.StatsReporter.LastReportedSimStats[15],
233 m =>
string.Format(
"{0}", m.GetValue())));
235 m_staticMonitors.Add(
238 "PendingDownloadsMonitor",
240 m => m.Scene.StatsReporter.LastReportedSimStats[17],
241 m =>
string.Format(
"{0}", m.GetValue())));
243 m_staticMonitors.Add(
246 "PendingUploadsMonitor",
248 m => m.Scene.StatsReporter.LastReportedSimStats[18],
249 m =>
string.Format(
"{0}", m.GetValue())));
251 m_staticMonitors.Add(
254 "TotalFrameTimeMonitor",
256 m => m.Scene.StatsReporter.LastReportedSimStats[8],
257 m =>
string.Format(
"{0} ms", m.GetValue())));
259 m_staticMonitors.Add(
262 "NetFrameTimeMonitor",
264 m => m.Scene.StatsReporter.LastReportedSimStats[9],
265 m =>
string.Format(
"{0} ms", m.GetValue())));
267 m_staticMonitors.Add(
270 "PhysicsFrameTimeMonitor",
271 "Physics Frame Time",
272 m => m.Scene.StatsReporter.LastReportedSimStats[10],
273 m =>
string.Format(
"{0} ms", m.GetValue())));
275 m_staticMonitors.Add(
278 "SimulationFrameTimeMonitor",
279 "Simulation Frame Time",
280 m => m.Scene.StatsReporter.LastReportedSimStats[12],
281 m =>
string.Format(
"{0} ms", m.GetValue())));
283 m_staticMonitors.Add(
286 "AgentFrameTimeMonitor",
288 m => m.Scene.StatsReporter.LastReportedSimStats[16],
289 m =>
string.Format(
"{0} ms", m.GetValue())));
291 m_staticMonitors.Add(
294 "ImagesFrameTimeMonitor",
296 m => m.Scene.StatsReporter.LastReportedSimStats[11],
297 m =>
string.Format(
"{0} ms", m.GetValue())));
299 m_staticMonitors.Add(
302 "SpareFrameTimeMonitor",
304 m => m.Scene.StatsReporter.LastReportedSimStats[38],
305 m =>
string.Format(
"{0} ms", m.GetValue())));
309 foreach (
IAlert alert
in m_alerts)
311 alert.OnTriggerAlert += OnTriggerAlert;
317 foreach (
IMonitor monitor
in m_staticMonitors)
319 MainConsole.Instance.OutputFormat(
320 "[MONITOR MODULE]: {0} reports {1} = {2}",
321 m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.
GetFriendlyValue());
324 foreach (KeyValuePair<string, float> tuple
in m_scene.StatsReporter.GetExtraSimStats())
326 MainConsole.Instance.OutputFormat(
327 "[MONITOR MODULE]: {0} reports {1} = {2}",
328 m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value);
334 foreach (
IAlert alert
in m_alerts)
344 if (request.ContainsKey(
"monitor"))
346 string monID = (string) request[
"monitor"];
348 foreach (
IMonitor monitor
in m_staticMonitors)
350 string elemName = monitor.ToString();
351 if (elemName.StartsWith(monitor.GetType().Namespace))
352 elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1);
354 if (elemName == monID || monitor.ToString() == monID)
356 Hashtable ereply3 =
new Hashtable();
358 ereply3[
"int_response_code"] = 404;
359 ereply3[
"str_response_string"] = monitor.GetValue().ToString();
360 ereply3[
"content_type"] =
"text/plain";
370 Hashtable ereply2 =
new Hashtable();
372 ereply2[
"int_response_code"] = 404;
373 ereply2[
"str_response_string"] =
"No such monitor";
374 ereply2[
"content_type"] =
"text/plain";
379 string xml =
"<data>";
380 foreach (
IMonitor monitor
in m_staticMonitors)
382 string elemName = monitor.GetName();
383 xml +=
"<" + elemName +
">" + monitor.GetValue().ToString() +
"</" + elemName +
">";
387 foreach (KeyValuePair<string, float> tuple
in m_scene.StatsReporter.GetExtraSimStats())
389 xml +=
"<" + tuple.Key +
">" + tuple.Value +
"</" + tuple.Key +
">";
394 Hashtable ereply =
new Hashtable();
396 ereply[
"int_response_code"] = 200;
397 ereply[
"str_response_string"] = xml;
398 ereply[
"content_type"] =
"text/xml";
403 void OnTriggerAlert(System.Type reporter,
string reason,
bool fatal)
405 m_log.Error(
"[Monitor] " + reporter.Name +
" for " + m_scene.RegionInfo.RegionName +
" reports " + reason +
" (Fatal: " + fatal +
")");
408 private List<Stat> registeredStats =
new List<Stat>();
409 private void MakeStat(
string pName,
string pUnitName, Action<Stat> act)
412 StatsManager.RegisterStat(tempStat);
413 registeredStats.Add(tempStat);
415 private void RegisterStatsManagerRegionStatistics()
417 MakeStat(
"RootAgents",
"avatars", (s) => { s.Value = m_scene.SceneGraph.GetRootAgentCount(); });
418 MakeStat(
"ChildAgents",
"avatars", (s) => { s.Value = m_scene.SceneGraph.GetChildAgentCount(); });
419 MakeStat(
"TotalPrims",
"objects", (s) => { s.Value = m_scene.SceneGraph.GetTotalObjectsCount(); });
420 MakeStat(
"ActivePrims",
"objects", (s) => { s.Value = m_scene.SceneGraph.GetActiveObjectsCount(); });
421 MakeStat(
"ActiveScripts",
"scripts", (s) => { s.Value = m_scene.SceneGraph.GetActiveScriptsCount(); });
423 MakeStat(
"TimeDilation",
"sec/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[0]; });
424 MakeStat(
"SimFPS",
"fps", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[1]; });
425 MakeStat(
"PhysicsFPS",
"fps", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[2]; });
426 MakeStat(
"AgentUpdates",
"updates/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[3]; });
427 MakeStat(
"FrameTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[8]; });
428 MakeStat(
"NetTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[9]; });
429 MakeStat(
"OtherTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[12]; });
430 MakeStat(
"PhysicsTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[10]; });
431 MakeStat(
"AgentTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[16]; });
432 MakeStat(
"ImageTime",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[11]; });
433 MakeStat(
"ScriptLines",
"lines/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[20]; });
434 MakeStat(
"SimSpareMS",
"ms/sec", (s) => { s.Value = m_scene.StatsReporter.LastReportedSimStats[21]; });
437 private void UnRegisterStatsManagerRegionStatistics()
439 foreach (
Stat stat
in registeredStats)
441 StatsManager.DeregisterStat(stat);
444 registeredStats.Clear();
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
string GetFriendlyValue()
Human readable value.
void DebugMonitors(string module, string[] args)
Holds individual statistic details
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
StatVerbosity
Verbosity of stat.
Hashtable StatsPage(Hashtable request)