aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDiva Canto2012-11-11 07:46:12 -0800
committerDiva Canto2012-11-11 07:46:12 -0800
commitf85d054bc6770ee133b6f86e4736432d555106e5 (patch)
treeb1e194c43e13ad57849be2bd58e41e6994d0cc0e /OpenSim
parentOne more module converted: InventoryArchiverModule. (diff)
downloadopensim-SC_OLD-f85d054bc6770ee133b6f86e4736432d555106e5.zip
opensim-SC_OLD-f85d054bc6770ee133b6f86e4736432d555106e5.tar.gz
opensim-SC_OLD-f85d054bc6770ee133b6f86e4736432d555106e5.tar.bz2
opensim-SC_OLD-f85d054bc6770ee133b6f86e4736432d555106e5.tar.xz
One more module converted: MonitorModule.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs211
1 files changed, 117 insertions, 94 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs b/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
index e411585..d2198f1 100644
--- a/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
@@ -38,10 +38,12 @@ using OpenSim.Region.CoreModules.Framework.Monitoring.Alerts;
38using OpenSim.Region.CoreModules.Framework.Monitoring.Monitors; 38using OpenSim.Region.CoreModules.Framework.Monitoring.Monitors;
39using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
41using Mono.Addins;
41 42
42namespace OpenSim.Region.CoreModules.Framework.Monitoring 43namespace OpenSim.Region.CoreModules.Framework.Monitoring
43{ 44{
44 public class MonitorModule : IRegionModule 45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
46 public class MonitorModule : INonSharedRegionModule
45 { 47 {
46 /// <summary> 48 /// <summary>
47 /// Is this module enabled? 49 /// Is this module enabled?
@@ -62,14 +64,14 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
62 private readonly List<IAlert> m_alerts = new List<IAlert>(); 64 private readonly List<IAlert> m_alerts = new List<IAlert>();
63 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 65 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
64 66
65 #region Implementation of IRegionModule
66
67 public MonitorModule() 67 public MonitorModule()
68 { 68 {
69 Enabled = true; 69 Enabled = true;
70 } 70 }
71 71
72 public void Initialise(Scene scene, IConfigSource source) 72 #region Implementation of INonSharedRegionModule
73
74 public void Initialise(IConfigSource source)
73 { 75 {
74 IConfig cnfg = source.Configs["Monitoring"]; 76 IConfig cnfg = source.Configs["Monitoring"];
75 77
@@ -79,6 +81,13 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
79 if (!Enabled) 81 if (!Enabled)
80 return; 82 return;
81 83
84 }
85
86 public void AddRegion(Scene scene)
87 {
88 if (!Enabled)
89 return;
90
82 m_scene = scene; 91 m_scene = scene;
83 92
84 m_scene.AddCommand("General", this, "monitor report", 93 m_scene.AddCommand("General", this, "monitor report",
@@ -89,101 +98,42 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
89 MainServer.Instance.AddHTTPHandler("/monitorstats/" + m_scene.RegionInfo.RegionID, StatsPage); 98 MainServer.Instance.AddHTTPHandler("/monitorstats/" + m_scene.RegionInfo.RegionID, StatsPage);
90 MainServer.Instance.AddHTTPHandler( 99 MainServer.Instance.AddHTTPHandler(
91 "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName), StatsPage); 100 "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName), StatsPage);
101
102 AddMonitors();
92 } 103 }
93 104
94 public void DebugMonitors(string module, string[] args) 105 public void RemoveRegion(Scene scene)
95 { 106 {
96 foreach (IMonitor monitor in m_staticMonitors) 107 if (!Enabled)
97 { 108 return;
98 MainConsole.Instance.OutputFormat(
99 "[MONITOR MODULE]: {0} reports {1} = {2}",
100 m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.GetFriendlyValue());
101 }
102 109
103 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats()) 110 MainServer.Instance.RemoveHTTPHandler("GET", "/monitorstats/" + m_scene.RegionInfo.RegionID);
104 { 111 MainServer.Instance.RemoveHTTPHandler("GET", "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName));
105 MainConsole.Instance.OutputFormat( 112 m_scene = null;
106 "[MONITOR MODULE]: {0} reports {1} = {2}",
107 m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value);
108 }
109 } 113 }
110 114
111 public void TestAlerts() 115 public void Close()
112 { 116 {
113 foreach (IAlert alert in m_alerts)
114 {
115 alert.Test();
116 }
117 } 117 }
118 118
119 public Hashtable StatsPage(Hashtable request) 119 public string Name
120 { 120 {
121 // If request was for a specific monitor 121 get { return "Region Health Monitoring Module"; }
122 // eg url/?monitor=Monitor.Name 122 }
123 if (request.ContainsKey("monitor"))
124 {
125 string monID = (string) request["monitor"];
126
127 foreach (IMonitor monitor in m_staticMonitors)
128 {
129 string elemName = monitor.ToString();
130 if (elemName.StartsWith(monitor.GetType().Namespace))
131 elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1);
132
133 if (elemName == monID || monitor.ToString() == monID)
134 {
135 Hashtable ereply3 = new Hashtable();
136
137 ereply3["int_response_code"] = 404; // 200 OK
138 ereply3["str_response_string"] = monitor.GetValue().ToString();
139 ereply3["content_type"] = "text/plain";
140
141 return ereply3;
142 }
143 }
144
145 // FIXME: Arguably this should also be done with dynamic monitors but I'm not sure what the above code
146 // is even doing. Why are we inspecting the type of the monitor???
147
148 // No monitor with that name
149 Hashtable ereply2 = new Hashtable();
150
151 ereply2["int_response_code"] = 404; // 200 OK
152 ereply2["str_response_string"] = "No such monitor";
153 ereply2["content_type"] = "text/plain";
154
155 return ereply2;
156 }
157
158 string xml = "<data>";
159 foreach (IMonitor monitor in m_staticMonitors)
160 {
161 string elemName = monitor.GetName();
162 xml += "<" + elemName + ">" + monitor.GetValue().ToString() + "</" + elemName + ">";
163// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue());
164 }
165
166 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats())
167 {
168 xml += "<" + tuple.Key + ">" + tuple.Value + "</" + tuple.Key + ">";
169 }
170
171 xml += "</data>";
172
173 Hashtable ereply = new Hashtable();
174
175 ereply["int_response_code"] = 200; // 200 OK
176 ereply["str_response_string"] = xml;
177 ereply["content_type"] = "text/xml";
178 123
179 return ereply; 124 public void RegionLoaded(Scene scene)
125 {
180 } 126 }
181 127
182 public void PostInitialise() 128 public Type ReplaceableInterface
183 { 129 {
184 if (!Enabled) 130 get { return null; }
185 return; 131 }
132
133 #endregion
186 134
135 public void AddMonitors()
136 {
187 m_staticMonitors.Add(new AgentCountMonitor(m_scene)); 137 m_staticMonitors.Add(new AgentCountMonitor(m_scene));
188 m_staticMonitors.Add(new ChildAgentCountMonitor(m_scene)); 138 m_staticMonitors.Add(new ChildAgentCountMonitor(m_scene));
189 m_staticMonitors.Add(new GCMemoryMonitor()); 139 m_staticMonitors.Add(new GCMemoryMonitor());
@@ -196,7 +146,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
196 m_staticMonitors.Add(new EventFrameMonitor(m_scene)); 146 m_staticMonitors.Add(new EventFrameMonitor(m_scene));
197 m_staticMonitors.Add(new LandFrameMonitor(m_scene)); 147 m_staticMonitors.Add(new LandFrameMonitor(m_scene));
198 m_staticMonitors.Add(new LastFrameTimeMonitor(m_scene)); 148 m_staticMonitors.Add(new LastFrameTimeMonitor(m_scene));
199 149
200 m_staticMonitors.Add( 150 m_staticMonitors.Add(
201 new GenericMonitor( 151 new GenericMonitor(
202 m_scene, 152 m_scene,
@@ -357,25 +307,98 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
357 } 307 }
358 } 308 }
359 309
360 void OnTriggerAlert(System.Type reporter, string reason, bool fatal) 310 public void DebugMonitors(string module, string[] args)
361 { 311 {
362 m_log.Error("[Monitor] " + reporter.Name + " for " + m_scene.RegionInfo.RegionName + " reports " + reason + " (Fatal: " + fatal + ")"); 312 foreach (IMonitor monitor in m_staticMonitors)
313 {
314 MainConsole.Instance.OutputFormat(
315 "[MONITOR MODULE]: {0} reports {1} = {2}",
316 m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.GetFriendlyValue());
317 }
318
319 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats())
320 {
321 MainConsole.Instance.OutputFormat(
322 "[MONITOR MODULE]: {0} reports {1} = {2}",
323 m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value);
324 }
363 } 325 }
364 326
365 public void Close() 327 public void TestAlerts()
366 { 328 {
329 foreach (IAlert alert in m_alerts)
330 {
331 alert.Test();
332 }
367 } 333 }
368 334
369 public string Name 335 public Hashtable StatsPage(Hashtable request)
370 { 336 {
371 get { return "Region Health Monitoring Module"; } 337 // If request was for a specific monitor
338 // eg url/?monitor=Monitor.Name
339 if (request.ContainsKey("monitor"))
340 {
341 string monID = (string) request["monitor"];
342
343 foreach (IMonitor monitor in m_staticMonitors)
344 {
345 string elemName = monitor.ToString();
346 if (elemName.StartsWith(monitor.GetType().Namespace))
347 elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1);
348
349 if (elemName == monID || monitor.ToString() == monID)
350 {
351 Hashtable ereply3 = new Hashtable();
352
353 ereply3["int_response_code"] = 404; // 200 OK
354 ereply3["str_response_string"] = monitor.GetValue().ToString();
355 ereply3["content_type"] = "text/plain";
356
357 return ereply3;
358 }
359 }
360
361 // FIXME: Arguably this should also be done with dynamic monitors but I'm not sure what the above code
362 // is even doing. Why are we inspecting the type of the monitor???
363
364 // No monitor with that name
365 Hashtable ereply2 = new Hashtable();
366
367 ereply2["int_response_code"] = 404; // 200 OK
368 ereply2["str_response_string"] = "No such monitor";
369 ereply2["content_type"] = "text/plain";
370
371 return ereply2;
372 }
373
374 string xml = "<data>";
375 foreach (IMonitor monitor in m_staticMonitors)
376 {
377 string elemName = monitor.GetName();
378 xml += "<" + elemName + ">" + monitor.GetValue().ToString() + "</" + elemName + ">";
379// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue());
380 }
381
382 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats())
383 {
384 xml += "<" + tuple.Key + ">" + tuple.Value + "</" + tuple.Key + ">";
385 }
386
387 xml += "</data>";
388
389 Hashtable ereply = new Hashtable();
390
391 ereply["int_response_code"] = 200; // 200 OK
392 ereply["str_response_string"] = xml;
393 ereply["content_type"] = "text/xml";
394
395 return ereply;
372 } 396 }
373 397
374 public bool IsSharedModule 398 void OnTriggerAlert(System.Type reporter, string reason, bool fatal)
375 { 399 {
376 get { return false; } 400 m_log.Error("[Monitor] " + reporter.Name + " for " + m_scene.RegionInfo.RegionName + " reports " + reason + " (Fatal: " + fatal + ")");
377 } 401 }
378 402
379 #endregion
380 } 403 }
381} 404}