From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- OpenSim/Framework/Monitoring/StatsManager.cs | 106 ++++++++++++++------------- 1 file changed, 57 insertions(+), 49 deletions(-) (limited to 'OpenSim/Framework/Monitoring/StatsManager.cs') diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs index 3136ee8..a6b341f 100644 --- a/OpenSim/Framework/Monitoring/StatsManager.cs +++ b/OpenSim/Framework/Monitoring/StatsManager.cs @@ -47,6 +47,8 @@ namespace OpenSim.Framework.Monitoring // Subcommand used to list other stats. public const string ListSubCommand = "list"; + public static string StatsPassword { get; set; } + // All subcommands public static HashSet SubCommands = new HashSet { AllSubCommand, ListSubCommand }; @@ -80,8 +82,7 @@ namespace OpenSim.Framework.Monitoring + "'all' will show all statistics.\n" + "A name will show statistics from that category.\n" + "A . name will show statistics from that category in that container.\n" - + "More than one name can be given separated by spaces.\n" - + "THIS STATS FACILITY IS EXPERIMENTAL AND DOES NOT YET CONTAIN ALL STATS", + + "More than one name can be given separated by spaces.\n", HandleShowStatsCommand); console.Commands.AddCommand( @@ -91,7 +92,6 @@ namespace OpenSim.Framework.Monitoring "show stats [list|all|([.])+", "Alias for 'stats show' command", HandleShowStatsCommand); - StatsLogger.RegisterConsoleCommands(console); } @@ -262,33 +262,36 @@ namespace OpenSim.Framework.Monitoring { OSDMap map = new OSDMap(); - foreach (string catName in RegisteredStats.Keys) + lock (RegisteredStats) { - // Do this category if null spec, "all" subcommand or category name matches passed parameter. - // Skip category if none of the above. - if (!(String.IsNullOrEmpty(pCategoryName) || pCategoryName == AllSubCommand || pCategoryName == catName)) - continue; - - OSDMap contMap = new OSDMap(); - foreach (string contName in RegisteredStats[catName].Keys) + foreach (string catName in RegisteredStats.Keys) { - if (!(string.IsNullOrEmpty(pContainerName) || pContainerName == AllSubCommand || pContainerName == contName)) + // Do this category if null spec, "all" subcommand or category name matches passed parameter. + // Skip category if none of the above. + if (!(String.IsNullOrEmpty(pCategoryName) || pCategoryName == AllSubCommand || pCategoryName == catName)) continue; - - OSDMap statMap = new OSDMap(); - SortedDictionary theStats = RegisteredStats[catName][contName]; - foreach (string statName in theStats.Keys) + OSDMap contMap = new OSDMap(); + foreach (string contName in RegisteredStats[catName].Keys) { - if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName)) + if (!(string.IsNullOrEmpty(pContainerName) || pContainerName == AllSubCommand || pContainerName == contName)) continue; - statMap.Add(statName, theStats[statName].ToOSDMap()); - } + OSDMap statMap = new OSDMap(); + + SortedDictionary theStats = RegisteredStats[catName][contName]; + foreach (string statName in theStats.Keys) + { + if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName)) + continue; + + statMap.Add(statName, theStats[statName].ToBriefOSDMap()); + } - contMap.Add(contName, statMap); + contMap.Add(contName, statMap); + } + map.Add(catName, contMap); } - map.Add(catName, contMap); } return map; @@ -301,6 +304,17 @@ namespace OpenSim.Framework.Monitoring int response_code = 200; string contenttype = "text/json"; + if (StatsPassword != String.Empty && (!request.ContainsKey("pass") || request["pass"].ToString() != StatsPassword)) + { + responsedata["int_response_code"] = response_code; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Access denied"; + responsedata["access_control_allow_origin"] = "*"; + + return responsedata; + } + string pCategoryName = StatsManager.AllSubCommand; string pContainerName = StatsManager.AllSubCommand; string pStatName = StatsManager.AllSubCommand; @@ -358,8 +372,8 @@ namespace OpenSim.Framework.Monitoring /// public static bool RegisterStat(Stat stat) { - SortedDictionary> category = null, newCategory; - SortedDictionary container = null, newContainer; + SortedDictionary> category = null; + SortedDictionary container = null; lock (RegisteredStats) { @@ -369,22 +383,15 @@ namespace OpenSim.Framework.Monitoring if (TryGetStatParents(stat, out category, out container)) return false; - // We take a copy-on-write approach here of replacing dictionaries when keys are added or removed. - // This means that we don't need to lock or copy them on iteration, which will be a much more - // common operation after startup. - if (container != null) - newContainer = new SortedDictionary(container); - else - newContainer = new SortedDictionary(); + if (container == null) + container = new SortedDictionary(); - if (category != null) - newCategory = new SortedDictionary>(category); - else - newCategory = new SortedDictionary>(); + if (category == null) + category = new SortedDictionary>(); - newContainer[stat.ShortName] = stat; - newCategory[stat.Container] = newContainer; - RegisteredStats[stat.Category] = newCategory; + container[stat.ShortName] = stat; + category[stat.Container] = container; + RegisteredStats[stat.Category] = category; } return true; @@ -397,23 +404,24 @@ namespace OpenSim.Framework.Monitoring /// public static bool DeregisterStat(Stat stat) { - SortedDictionary> category = null, newCategory; - SortedDictionary container = null, newContainer; + SortedDictionary> category = null; + SortedDictionary container = null; lock (RegisteredStats) { if (!TryGetStatParents(stat, out category, out container)) return false; - newContainer = new SortedDictionary(container); - newContainer.Remove(stat.ShortName); - - newCategory = new SortedDictionary>(category); - newCategory.Remove(stat.Container); - - newCategory[stat.Container] = newContainer; - RegisteredStats[stat.Category] = newCategory; - + if(container != null) + { + container.Remove(stat.ShortName); + if(category != null && container.Count == 0) + { + category.Remove(stat.Container); + if(category.Count == 0) + RegisteredStats.Remove(stat.Category); + } + } return true; } } @@ -554,4 +562,4 @@ namespace OpenSim.Framework.Monitoring Debug, Info } -} \ No newline at end of file +} -- cgit v1.1