From 8ec10f9ca83385eed3f2947b44dd61514a375e7c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 18 Feb 2025 12:37:25 +0000 Subject: [PATCH] remove the new xmlrpc grid stats. xmlrcp is obsolete; change refresh time to 15minutes; cosmetics --- .../Server/Handlers/Grid/GridInfoHandlers.cs | 85 ++++++------------- .../Grid/GridInfoServerInConnector.cs | 1 - bin/Robust.HG.ini.example | 2 +- bin/Robust.ini.example | 3 +- 4 files changed, 29 insertions(+), 62 deletions(-) diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs index ff0c78fdf3..7ed234e08e 100644 --- a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs +++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs @@ -47,8 +47,8 @@ namespace OpenSim.Server.Handlers.Grid { private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IConfigSource m_Config; - private Dictionary _info = new Dictionary(); - private Dictionary _stats = new Dictionary(); + private Dictionary _info = []; + private Dictionary _stats = []; private byte[] cachedJsonAnswer = null; private byte[] cachedRestAnswer = null; private byte[] cachedStatAnswer = null; @@ -79,6 +79,7 @@ namespace OpenSim.Server.Handlers.Grid IConfig gridCfg = configSource.Configs["GridInfoService"]; stats_available = !gridCfg.GetBoolean("DisableStatsEndpoint", false); + _lastrun = 0; if (stats_available) { @@ -87,13 +88,9 @@ namespace OpenSim.Server.Handlers.Grid { ServiceBase serviceBase = new(configSource); - string dllName = String.Empty; - string connString = String.Empty; - if (dllName.Length == 0) - dllName = dbConfig.GetString("StorageProvider", String.Empty); - if (connString.Length == 0) - connString = dbConfig.GetString("ConnectionString", String.Empty); + string dllName = dbConfig.GetString("StorageProvider", String.Empty); + string connString = dbConfig.GetString("ConnectionString", String.Empty); if (dllName.Length != 0 && connString.Length != 0) { @@ -105,7 +102,6 @@ namespace OpenSim.Server.Handlers.Grid { stats_available = true; _log.Debug("[GRID INFO SERVICE]: Grid Stats enabled"); - GetGridStats(); } } if (!stats_available) @@ -139,8 +135,7 @@ namespace OpenSim.Server.Handlers.Grid _info.TryGetValue("home", out string tmp); - tmp = Util.GetConfigVarFromSections(m_Config, "HomeURI", - new string[] { "Startup", "Hypergrid" }, tmp); + tmp = Util.GetConfigVarFromSections(m_Config, "HomeURI", ["Startup", "Hypergrid"], tmp); if (string.IsNullOrEmpty(tmp)) { @@ -151,8 +146,7 @@ namespace OpenSim.Server.Handlers.Grid if (!string.IsNullOrEmpty(tmp)) _info["home"] = OSD.FromString(tmp); - tmp = Util.GetConfigVarFromSections(m_Config, "HomeURIAlias", - new string[] { "Startup", "Hypergrid" }, string.Empty); + tmp = Util.GetConfigVarFromSections(m_Config, "HomeURIAlias", ["Startup", "Hypergrid"], string.Empty); if (!string.IsNullOrEmpty(tmp)) _info["homealias"] = OSD.FromString(tmp); @@ -162,8 +156,7 @@ namespace OpenSim.Server.Handlers.Grid if (!string.IsNullOrEmpty(tmp)) _info["gatekeeper"] = OSD.FromString(tmp); - tmp = Util.GetConfigVarFromSections(m_Config, "GatekeeperURIAlias", - new string[] { "Startup", "Hypergrid" }, string.Empty); + tmp = Util.GetConfigVarFromSections(m_Config, "GatekeeperURIAlias", ["Startup", "Hypergrid"], string.Empty); if (!string.IsNullOrEmpty(tmp)) _info["gatekeeperalias"] = OSD.FromString(tmp); @@ -190,7 +183,7 @@ namespace OpenSim.Server.Handlers.Grid public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient) { XmlRpcResponse response = new XmlRpcResponse(); - Hashtable responseData = new Hashtable(); + Hashtable responseData = []; _log.Debug("[GRID INFO SERVICE]: Request for grid info"); @@ -271,23 +264,23 @@ namespace OpenSim.Server.Handlers.Grid httpResponse.RawBuffer = cachedJsonAnswer; } - public void GetGridStats() + public void GetGridStats(int now) { int region_count = 0; int active_users = 0; int residents = 0; - _stats["region_count"] = region_count.ToString(); - _stats["active_users"] = active_users.ToString(); - _stats["residents"] = residents.ToString(); - - int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; - _lastrun = epoch; - try { // Fetch region data List regions = m_Database_regions.GetOnlineRegions(UUID.Zero); + foreach (RegionData region in regions) + { + // Count individual region equivalent + region_count += (region.sizeX / 256) * (region.sizeY / 256); + } + regions = null; + // Fetch all grid users, can't do a simple query unfortunately GridUserData[] gridusers = m_Database_griduser.GetAll(string.Empty); @@ -305,47 +298,21 @@ namespace OpenSim.Server.Handlers.Grid continue; // Count if last login was within the last 30 days - if (last_login > (epoch - 2592000)) + if (last_login > (now - 2592000)) active_users++; } } - - foreach (RegionData region in regions) - { - // Count individual region equivalent - region_count += (region.sizeX / 256) * (region.sizeY / 256); - } - - _stats["residents"] = residents.ToString(); - _stats["active_users"] = active_users.ToString(); - _stats["region_count"] = region_count.ToString(); } catch (Exception ex) { _log.ErrorFormat("[GRID INFO SERVICE]: Could not fetch grid stats: {0}", ex.Message); } - } - public XmlRpcResponse GridStatsHandler(XmlRpcRequest request, IPEndPoint remoteClient) - { - XmlRpcResponse response = new(); - Hashtable responseData = []; + _stats["residents"] = residents.ToString(); + _stats["active_users"] = active_users.ToString(); + _stats["region_count"] = region_count.ToString(); - // Only fetch new stats if the last run is 5 minutes old since this is heavy db stuff - int Epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; - if ((Epoch - 300) > _lastrun) - GetGridStats(); - - _log.DebugFormat("[GRID INFO SERVICE]: Request for grid stats from {0}", remoteClient.Address.ToString()); - - foreach (KeyValuePair k in _stats) - { - responseData[k.Key] = k.Value; - } - response.Value = responseData; - - return response; - + _lastrun = now; } public void RestGridStatsHandler(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) @@ -357,12 +324,12 @@ namespace OpenSim.Server.Handlers.Grid return; } - // Only fetch new stats if the last run is 5 minutes old since this is heavy db stuff - int Epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; + // Only fetch new stats if the last run is 15 minutes old since this is heavy db stuff + int now = Util.UnixTimeSinceEpoch(); - if (cachedStatAnswer == null || (Epoch - 300) > _lastrun) + if (cachedStatAnswer == null || (now - 900) > _lastrun) { - GetGridStats(); + GetGridStats(now); osUTF8 osb = OSUTF8Cached.Acquire(); osb.AppendASCII(""); foreach (KeyValuePair k in _stats) diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs index 0ec3506053..8dda9741b9 100644 --- a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs +++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs @@ -59,7 +59,6 @@ namespace OpenSim.Server.Handlers.Grid if (!stats_disabled) { server.AddSimpleStreamHandler(new SimpleStreamHandler("/get_grid_stats", handlers.RestGridStatsHandler)); - server.AddXmlRPCHandler("get_grid_stats", handlers.GridStatsHandler, false); } } } diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 0c8089f8c1..8b89a81cd5 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -688,7 +688,7 @@ ;[AGENT_NAME] will be converted to Firstname.LastName by viewers ; web_profile_url = http://webprofilesurl:ItsPort?name=[AGENT_NAME] - ; By default a xmlrpc handler outputs some grid statistics via /get_grid_stats This can be turned off here + ; http REST handler /get_grid_stats may output some grid statistics This can be turned off here ;DisableStatsEndpoint = true [GatekeeperService] diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index b7f4c86361..ea9d1183be 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -605,9 +605,10 @@ ;[AGENT_NAME] will be converted to Firstname.LastName by viewers ; web_profile_url = http://webprofilesurl:ItsPort?name=[AGENT_NAME] - ; By default a xmlrpc handler outputs some grid statistics via /get_grid_stats This can be turned off here + ; http REST handler /get_grid_stats may output some grid statistics This can be turned off here ;DisableStatsEndpoint = true + [Messaging] ; OfflineIM OfflineIMService = "OpenSim.Addons.OfflineIM.dll:OfflineIMService"