From f85d054bc6770ee133b6f86e4736432d555106e5 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 11 Nov 2012 07:46:12 -0800 Subject: One more module converted: MonitorModule. --- .../Framework/Monitoring/MonitorModule.cs | 211 ++++++++++++--------- 1 file 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; using OpenSim.Region.CoreModules.Framework.Monitoring.Monitors; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using Mono.Addins; namespace OpenSim.Region.CoreModules.Framework.Monitoring { - public class MonitorModule : IRegionModule + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class MonitorModule : INonSharedRegionModule { /// /// Is this module enabled? @@ -62,14 +64,14 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring private readonly List m_alerts = new List(); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - #region Implementation of IRegionModule - public MonitorModule() { Enabled = true; } - public void Initialise(Scene scene, IConfigSource source) + #region Implementation of INonSharedRegionModule + + public void Initialise(IConfigSource source) { IConfig cnfg = source.Configs["Monitoring"]; @@ -79,6 +81,13 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring if (!Enabled) return; + } + + public void AddRegion(Scene scene) + { + if (!Enabled) + return; + m_scene = scene; m_scene.AddCommand("General", this, "monitor report", @@ -89,101 +98,42 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring MainServer.Instance.AddHTTPHandler("/monitorstats/" + m_scene.RegionInfo.RegionID, StatsPage); MainServer.Instance.AddHTTPHandler( "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName), StatsPage); + + AddMonitors(); } - public void DebugMonitors(string module, string[] args) + public void RemoveRegion(Scene scene) { - foreach (IMonitor monitor in m_staticMonitors) - { - MainConsole.Instance.OutputFormat( - "[MONITOR MODULE]: {0} reports {1} = {2}", - m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.GetFriendlyValue()); - } + if (!Enabled) + return; - foreach (KeyValuePair tuple in m_scene.StatsReporter.GetExtraSimStats()) - { - MainConsole.Instance.OutputFormat( - "[MONITOR MODULE]: {0} reports {1} = {2}", - m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value); - } + MainServer.Instance.RemoveHTTPHandler("GET", "/monitorstats/" + m_scene.RegionInfo.RegionID); + MainServer.Instance.RemoveHTTPHandler("GET", "/monitorstats/" + Uri.EscapeDataString(m_scene.RegionInfo.RegionName)); + m_scene = null; } - public void TestAlerts() + public void Close() { - foreach (IAlert alert in m_alerts) - { - alert.Test(); - } } - public Hashtable StatsPage(Hashtable request) + public string Name { - // If request was for a specific monitor - // eg url/?monitor=Monitor.Name - if (request.ContainsKey("monitor")) - { - string monID = (string) request["monitor"]; - - foreach (IMonitor monitor in m_staticMonitors) - { - string elemName = monitor.ToString(); - if (elemName.StartsWith(monitor.GetType().Namespace)) - elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1); - - if (elemName == monID || monitor.ToString() == monID) - { - Hashtable ereply3 = new Hashtable(); - - ereply3["int_response_code"] = 404; // 200 OK - ereply3["str_response_string"] = monitor.GetValue().ToString(); - ereply3["content_type"] = "text/plain"; - - return ereply3; - } - } - - // FIXME: Arguably this should also be done with dynamic monitors but I'm not sure what the above code - // is even doing. Why are we inspecting the type of the monitor??? - - // No monitor with that name - Hashtable ereply2 = new Hashtable(); - - ereply2["int_response_code"] = 404; // 200 OK - ereply2["str_response_string"] = "No such monitor"; - ereply2["content_type"] = "text/plain"; - - return ereply2; - } - - string xml = ""; - foreach (IMonitor monitor in m_staticMonitors) - { - string elemName = monitor.GetName(); - xml += "<" + elemName + ">" + monitor.GetValue().ToString() + ""; -// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue()); - } - - foreach (KeyValuePair tuple in m_scene.StatsReporter.GetExtraSimStats()) - { - xml += "<" + tuple.Key + ">" + tuple.Value + ""; - } - - xml += ""; - - Hashtable ereply = new Hashtable(); - - ereply["int_response_code"] = 200; // 200 OK - ereply["str_response_string"] = xml; - ereply["content_type"] = "text/xml"; + get { return "Region Health Monitoring Module"; } + } - return ereply; + public void RegionLoaded(Scene scene) + { } - public void PostInitialise() + public Type ReplaceableInterface { - if (!Enabled) - return; + get { return null; } + } + + #endregion + public void AddMonitors() + { m_staticMonitors.Add(new AgentCountMonitor(m_scene)); m_staticMonitors.Add(new ChildAgentCountMonitor(m_scene)); m_staticMonitors.Add(new GCMemoryMonitor()); @@ -196,7 +146,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring m_staticMonitors.Add(new EventFrameMonitor(m_scene)); m_staticMonitors.Add(new LandFrameMonitor(m_scene)); m_staticMonitors.Add(new LastFrameTimeMonitor(m_scene)); - + m_staticMonitors.Add( new GenericMonitor( m_scene, @@ -357,25 +307,98 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring } } - void OnTriggerAlert(System.Type reporter, string reason, bool fatal) + public void DebugMonitors(string module, string[] args) { - m_log.Error("[Monitor] " + reporter.Name + " for " + m_scene.RegionInfo.RegionName + " reports " + reason + " (Fatal: " + fatal + ")"); + foreach (IMonitor monitor in m_staticMonitors) + { + MainConsole.Instance.OutputFormat( + "[MONITOR MODULE]: {0} reports {1} = {2}", + m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.GetFriendlyValue()); + } + + foreach (KeyValuePair tuple in m_scene.StatsReporter.GetExtraSimStats()) + { + MainConsole.Instance.OutputFormat( + "[MONITOR MODULE]: {0} reports {1} = {2}", + m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value); + } } - public void Close() + public void TestAlerts() { + foreach (IAlert alert in m_alerts) + { + alert.Test(); + } } - public string Name + public Hashtable StatsPage(Hashtable request) { - get { return "Region Health Monitoring Module"; } + // If request was for a specific monitor + // eg url/?monitor=Monitor.Name + if (request.ContainsKey("monitor")) + { + string monID = (string) request["monitor"]; + + foreach (IMonitor monitor in m_staticMonitors) + { + string elemName = monitor.ToString(); + if (elemName.StartsWith(monitor.GetType().Namespace)) + elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1); + + if (elemName == monID || monitor.ToString() == monID) + { + Hashtable ereply3 = new Hashtable(); + + ereply3["int_response_code"] = 404; // 200 OK + ereply3["str_response_string"] = monitor.GetValue().ToString(); + ereply3["content_type"] = "text/plain"; + + return ereply3; + } + } + + // FIXME: Arguably this should also be done with dynamic monitors but I'm not sure what the above code + // is even doing. Why are we inspecting the type of the monitor??? + + // No monitor with that name + Hashtable ereply2 = new Hashtable(); + + ereply2["int_response_code"] = 404; // 200 OK + ereply2["str_response_string"] = "No such monitor"; + ereply2["content_type"] = "text/plain"; + + return ereply2; + } + + string xml = ""; + foreach (IMonitor monitor in m_staticMonitors) + { + string elemName = monitor.GetName(); + xml += "<" + elemName + ">" + monitor.GetValue().ToString() + ""; +// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue()); + } + + foreach (KeyValuePair tuple in m_scene.StatsReporter.GetExtraSimStats()) + { + xml += "<" + tuple.Key + ">" + tuple.Value + ""; + } + + xml += ""; + + Hashtable ereply = new Hashtable(); + + ereply["int_response_code"] = 200; // 200 OK + ereply["str_response_string"] = xml; + ereply["content_type"] = "text/xml"; + + return ereply; } - public bool IsSharedModule + void OnTriggerAlert(System.Type reporter, string reason, bool fatal) { - get { return false; } + m_log.Error("[Monitor] " + reporter.Name + " for " + m_scene.RegionInfo.RegionName + " reports " + reason + " (Fatal: " + fatal + ")"); } - - #endregion + } } -- cgit v1.1