diff options
author | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
---|---|---|
committer | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
commit | 159fcbf150b7da0e229b29aa7b94793484543d12 (patch) | |
tree | b8c0ff3b4c758a3fba8315b556c923ef4c02a185 /OpenSim/Framework/Monitoring | |
parent | Merge commit '68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76' (diff) | |
parent | Merge branch 'master' into careminster (diff) | |
download | opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.zip opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.gz opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.bz2 opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.xz |
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Conflicts:
OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
Diffstat (limited to 'OpenSim/Framework/Monitoring')
-rw-r--r-- | OpenSim/Framework/Monitoring/BaseStatsCollector.cs | 14 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/Checks/Check.cs | 118 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/ChecksManager.cs | 262 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/MemoryWatchdog.cs | 8 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/Properties/AssemblyInfo.cs | 2 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/ServerStatsCollector.cs | 349 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs | 25 | ||||
-rwxr-xr-x | OpenSim/Framework/Monitoring/Stats/CounterStat.cs | 163 | ||||
-rwxr-xr-x | OpenSim/Framework/Monitoring/Stats/EventHistogram.cs | 173 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/Stats/PercentageStat.cs | 16 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/Stats/Stat.cs | 79 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/StatsLogger.cs | 108 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/StatsManager.cs | 334 | ||||
-rw-r--r-- | OpenSim/Framework/Monitoring/Watchdog.cs | 1 |
14 files changed, 1415 insertions, 237 deletions
diff --git a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs index 23dba09..96536e8 100644 --- a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs +++ b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -44,16 +44,16 @@ namespace OpenSim.Framework.Monitoring | |||
44 | sb.Append("MEMORY STATISTICS"); | 44 | sb.Append("MEMORY STATISTICS"); |
45 | sb.Append(Environment.NewLine); | 45 | sb.Append(Environment.NewLine); |
46 | sb.AppendFormat( | 46 | sb.AppendFormat( |
47 | "Allocated to OpenSim objects: {0} MB\n", | 47 | "Heap allocated to OpenSim : {0} MB\n", |
48 | Math.Round(GC.GetTotalMemory(false) / 1024.0 / 1024.0)); | 48 | Math.Round(GC.GetTotalMemory(false) / 1024.0 / 1024.0)); |
49 | 49 | ||
50 | sb.AppendFormat( | 50 | sb.AppendFormat( |
51 | "OpenSim last object memory churn : {0} MB/s\n", | 51 | "Last heap allocation rate : {0} MB/s\n", |
52 | Math.Round((MemoryWatchdog.LastMemoryChurn * 1000) / 1024.0 / 1024, 3)); | 52 | Math.Round((MemoryWatchdog.LastHeapAllocationRate * 1000) / 1024.0 / 1024, 3)); |
53 | 53 | ||
54 | sb.AppendFormat( | 54 | sb.AppendFormat( |
55 | "OpenSim average object memory churn : {0} MB/s\n", | 55 | "Average heap allocation rate: {0} MB/s\n", |
56 | Math.Round((MemoryWatchdog.AverageMemoryChurn * 1000) / 1024.0 / 1024, 3)); | 56 | Math.Round((MemoryWatchdog.AverageHeapAllocationRate * 1000) / 1024.0 / 1024, 3)); |
57 | 57 | ||
58 | Process myprocess = Process.GetCurrentProcess(); | 58 | Process myprocess = Process.GetCurrentProcess(); |
59 | if (!myprocess.HasExited) | 59 | if (!myprocess.HasExited) |
diff --git a/OpenSim/Framework/Monitoring/Checks/Check.cs b/OpenSim/Framework/Monitoring/Checks/Check.cs new file mode 100644 index 0000000..594386a --- /dev/null +++ b/OpenSim/Framework/Monitoring/Checks/Check.cs | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Text; | ||
30 | |||
31 | namespace OpenSim.Framework.Monitoring | ||
32 | { | ||
33 | public class Check | ||
34 | { | ||
35 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
36 | |||
37 | public static readonly char[] DisallowedShortNameCharacters = { '.' }; | ||
38 | |||
39 | /// <summary> | ||
40 | /// Category of this stat (e.g. cache, scene, etc). | ||
41 | /// </summary> | ||
42 | public string Category { get; private set; } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Containing name for this stat. | ||
46 | /// FIXME: In the case of a scene, this is currently the scene name (though this leaves | ||
47 | /// us with a to-be-resolved problem of non-unique region names). | ||
48 | /// </summary> | ||
49 | /// <value> | ||
50 | /// The container. | ||
51 | /// </value> | ||
52 | public string Container { get; private set; } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Action used to check whether alert should go off. | ||
56 | /// </summary> | ||
57 | /// <remarks> | ||
58 | /// Should return true if check passes. False otherwise. | ||
59 | /// </remarks> | ||
60 | public Func<Check, bool> CheckFunc { get; private set; } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Message from the last failure, if any. If there is no message or no failure then will be null. | ||
64 | /// </summary> | ||
65 | /// <remarks> | ||
66 | /// Should be set by the CheckFunc when applicable. | ||
67 | /// </remarks> | ||
68 | public string LastFailureMessage { get; set; } | ||
69 | |||
70 | public StatVerbosity Verbosity { get; private set; } | ||
71 | public string ShortName { get; private set; } | ||
72 | public string Name { get; private set; } | ||
73 | public string Description { get; private set; } | ||
74 | |||
75 | public Check( | ||
76 | string shortName, | ||
77 | string name, | ||
78 | string description, | ||
79 | string category, | ||
80 | string container, | ||
81 | Func<Check, bool> checkFunc, | ||
82 | StatVerbosity verbosity) | ||
83 | { | ||
84 | if (ChecksManager.SubCommands.Contains(category)) | ||
85 | throw new Exception( | ||
86 | string.Format("Alert cannot be in category '{0}' since this is reserved for a subcommand", category)); | ||
87 | |||
88 | foreach (char c in DisallowedShortNameCharacters) | ||
89 | { | ||
90 | if (shortName.IndexOf(c) != -1) | ||
91 | throw new Exception(string.Format("Alert name {0} cannot contain character {1}", shortName, c)); | ||
92 | } | ||
93 | |||
94 | ShortName = shortName; | ||
95 | Name = name; | ||
96 | Description = description; | ||
97 | Category = category; | ||
98 | Container = container; | ||
99 | CheckFunc = checkFunc; | ||
100 | Verbosity = verbosity; | ||
101 | } | ||
102 | |||
103 | public bool CheckIt() | ||
104 | { | ||
105 | return CheckFunc(this); | ||
106 | } | ||
107 | |||
108 | public virtual string ToConsoleString() | ||
109 | { | ||
110 | return string.Format( | ||
111 | "{0}.{1}.{2} - {3}", | ||
112 | Category, | ||
113 | Container, | ||
114 | ShortName, | ||
115 | Description); | ||
116 | } | ||
117 | } | ||
118 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Monitoring/ChecksManager.cs b/OpenSim/Framework/Monitoring/ChecksManager.cs new file mode 100644 index 0000000..e4a7f8c --- /dev/null +++ b/OpenSim/Framework/Monitoring/ChecksManager.cs | |||
@@ -0,0 +1,262 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | |||
35 | namespace OpenSim.Framework.Monitoring | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Static class used to register/deregister checks on runtime conditions. | ||
39 | /// </summary> | ||
40 | public static class ChecksManager | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | // Subcommand used to list other stats. | ||
45 | public const string ListSubCommand = "list"; | ||
46 | |||
47 | // All subcommands | ||
48 | public static HashSet<string> SubCommands = new HashSet<string> { ListSubCommand }; | ||
49 | |||
50 | /// <summary> | ||
51 | /// Checks categorized by category/container/shortname | ||
52 | /// </summary> | ||
53 | /// <remarks> | ||
54 | /// Do not add or remove directly from this dictionary. | ||
55 | /// </remarks> | ||
56 | public static SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Check>>> RegisteredChecks | ||
57 | = new SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Check>>>(); | ||
58 | |||
59 | public static void RegisterConsoleCommands(ICommandConsole console) | ||
60 | { | ||
61 | console.Commands.AddCommand( | ||
62 | "General", | ||
63 | false, | ||
64 | "show checks", | ||
65 | "show checks", | ||
66 | "Show checks configured for this server", | ||
67 | "If no argument is specified then info on all checks will be shown.\n" | ||
68 | + "'list' argument will show check categories.\n" | ||
69 | + "THIS FACILITY IS EXPERIMENTAL", | ||
70 | HandleShowchecksCommand); | ||
71 | } | ||
72 | |||
73 | public static void HandleShowchecksCommand(string module, string[] cmd) | ||
74 | { | ||
75 | ICommandConsole con = MainConsole.Instance; | ||
76 | |||
77 | if (cmd.Length > 2) | ||
78 | { | ||
79 | foreach (string name in cmd.Skip(2)) | ||
80 | { | ||
81 | string[] components = name.Split('.'); | ||
82 | |||
83 | string categoryName = components[0]; | ||
84 | // string containerName = components.Length > 1 ? components[1] : null; | ||
85 | |||
86 | if (categoryName == ListSubCommand) | ||
87 | { | ||
88 | con.Output("check categories available are:"); | ||
89 | |||
90 | foreach (string category in RegisteredChecks.Keys) | ||
91 | con.OutputFormat(" {0}", category); | ||
92 | } | ||
93 | // else | ||
94 | // { | ||
95 | // SortedDictionary<string, SortedDictionary<string, Check>> category; | ||
96 | // if (!Registeredchecks.TryGetValue(categoryName, out category)) | ||
97 | // { | ||
98 | // con.OutputFormat("No such category as {0}", categoryName); | ||
99 | // } | ||
100 | // else | ||
101 | // { | ||
102 | // if (String.IsNullOrEmpty(containerName)) | ||
103 | // { | ||
104 | // OutputConfiguredToConsole(con, category); | ||
105 | // } | ||
106 | // else | ||
107 | // { | ||
108 | // SortedDictionary<string, Check> container; | ||
109 | // if (category.TryGetValue(containerName, out container)) | ||
110 | // { | ||
111 | // OutputContainerChecksToConsole(con, container); | ||
112 | // } | ||
113 | // else | ||
114 | // { | ||
115 | // con.OutputFormat("No such container {0} in category {1}", containerName, categoryName); | ||
116 | // } | ||
117 | // } | ||
118 | // } | ||
119 | // } | ||
120 | } | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | OutputAllChecksToConsole(con); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Registers a statistic. | ||
130 | /// </summary> | ||
131 | /// <param name='stat'></param> | ||
132 | /// <returns></returns> | ||
133 | public static bool RegisterCheck(Check check) | ||
134 | { | ||
135 | SortedDictionary<string, SortedDictionary<string, Check>> category = null, newCategory; | ||
136 | SortedDictionary<string, Check> container = null, newContainer; | ||
137 | |||
138 | lock (RegisteredChecks) | ||
139 | { | ||
140 | // Check name is not unique across category/container/shortname key. | ||
141 | // XXX: For now just return false. This is to avoid problems in regression tests where all tests | ||
142 | // in a class are run in the same instance of the VM. | ||
143 | if (TryGetCheckParents(check, out category, out container)) | ||
144 | return false; | ||
145 | |||
146 | // We take a copy-on-write approach here of replacing dictionaries when keys are added or removed. | ||
147 | // This means that we don't need to lock or copy them on iteration, which will be a much more | ||
148 | // common operation after startup. | ||
149 | if (container != null) | ||
150 | newContainer = new SortedDictionary<string, Check>(container); | ||
151 | else | ||
152 | newContainer = new SortedDictionary<string, Check>(); | ||
153 | |||
154 | if (category != null) | ||
155 | newCategory = new SortedDictionary<string, SortedDictionary<string, Check>>(category); | ||
156 | else | ||
157 | newCategory = new SortedDictionary<string, SortedDictionary<string, Check>>(); | ||
158 | |||
159 | newContainer[check.ShortName] = check; | ||
160 | newCategory[check.Container] = newContainer; | ||
161 | RegisteredChecks[check.Category] = newCategory; | ||
162 | } | ||
163 | |||
164 | return true; | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Deregister an check | ||
169 | /// </summary>> | ||
170 | /// <param name='stat'></param> | ||
171 | /// <returns></returns> | ||
172 | public static bool DeregisterCheck(Check check) | ||
173 | { | ||
174 | SortedDictionary<string, SortedDictionary<string, Check>> category = null, newCategory; | ||
175 | SortedDictionary<string, Check> container = null, newContainer; | ||
176 | |||
177 | lock (RegisteredChecks) | ||
178 | { | ||
179 | if (!TryGetCheckParents(check, out category, out container)) | ||
180 | return false; | ||
181 | |||
182 | newContainer = new SortedDictionary<string, Check>(container); | ||
183 | newContainer.Remove(check.ShortName); | ||
184 | |||
185 | newCategory = new SortedDictionary<string, SortedDictionary<string, Check>>(category); | ||
186 | newCategory.Remove(check.Container); | ||
187 | |||
188 | newCategory[check.Container] = newContainer; | ||
189 | RegisteredChecks[check.Category] = newCategory; | ||
190 | |||
191 | return true; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | public static bool TryGetCheckParents( | ||
196 | Check check, | ||
197 | out SortedDictionary<string, SortedDictionary<string, Check>> category, | ||
198 | out SortedDictionary<string, Check> container) | ||
199 | { | ||
200 | category = null; | ||
201 | container = null; | ||
202 | |||
203 | lock (RegisteredChecks) | ||
204 | { | ||
205 | if (RegisteredChecks.TryGetValue(check.Category, out category)) | ||
206 | { | ||
207 | if (category.TryGetValue(check.Container, out container)) | ||
208 | { | ||
209 | if (container.ContainsKey(check.ShortName)) | ||
210 | return true; | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | |||
215 | return false; | ||
216 | } | ||
217 | |||
218 | public static void CheckChecks() | ||
219 | { | ||
220 | lock (RegisteredChecks) | ||
221 | { | ||
222 | foreach (SortedDictionary<string, SortedDictionary<string, Check>> category in RegisteredChecks.Values) | ||
223 | { | ||
224 | foreach (SortedDictionary<string, Check> container in category.Values) | ||
225 | { | ||
226 | foreach (Check check in container.Values) | ||
227 | { | ||
228 | if (!check.CheckIt()) | ||
229 | m_log.WarnFormat( | ||
230 | "[CHECKS MANAGER]: Check {0}.{1}.{2} failed with message {3}", check.Category, check.Container, check.ShortName, check.LastFailureMessage); | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | private static void OutputAllChecksToConsole(ICommandConsole con) | ||
238 | { | ||
239 | foreach (var category in RegisteredChecks.Values) | ||
240 | { | ||
241 | OutputCategoryChecksToConsole(con, category); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | private static void OutputCategoryChecksToConsole( | ||
246 | ICommandConsole con, SortedDictionary<string, SortedDictionary<string, Check>> category) | ||
247 | { | ||
248 | foreach (var container in category.Values) | ||
249 | { | ||
250 | OutputContainerChecksToConsole(con, container); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | private static void OutputContainerChecksToConsole(ICommandConsole con, SortedDictionary<string, Check> container) | ||
255 | { | ||
256 | foreach (Check check in container.Values) | ||
257 | { | ||
258 | con.Output(check.ToConsoleString()); | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Monitoring/MemoryWatchdog.cs b/OpenSim/Framework/Monitoring/MemoryWatchdog.cs index c6010cd..c474622 100644 --- a/OpenSim/Framework/Monitoring/MemoryWatchdog.cs +++ b/OpenSim/Framework/Monitoring/MemoryWatchdog.cs | |||
@@ -60,17 +60,17 @@ namespace OpenSim.Framework.Monitoring | |||
60 | private static bool m_enabled; | 60 | private static bool m_enabled; |
61 | 61 | ||
62 | /// <summary> | 62 | /// <summary> |
63 | /// Last memory churn in bytes per millisecond. | 63 | /// Average heap allocation rate in bytes per millisecond. |
64 | /// </summary> | 64 | /// </summary> |
65 | public static double AverageMemoryChurn | 65 | public static double AverageHeapAllocationRate |
66 | { | 66 | { |
67 | get { if (m_samples.Count > 0) return m_samples.Average(); else return 0; } | 67 | get { if (m_samples.Count > 0) return m_samples.Average(); else return 0; } |
68 | } | 68 | } |
69 | 69 | ||
70 | /// <summary> | 70 | /// <summary> |
71 | /// Average memory churn in bytes per millisecond. | 71 | /// Last heap allocation in bytes |
72 | /// </summary> | 72 | /// </summary> |
73 | public static double LastMemoryChurn | 73 | public static double LastHeapAllocationRate |
74 | { | 74 | { |
75 | get { if (m_samples.Count > 0) return m_samples.Last(); else return 0; } | 75 | get { if (m_samples.Count > 0) return m_samples.Last(); else return 0; } |
76 | } | 76 | } |
diff --git a/OpenSim/Framework/Monitoring/Properties/AssemblyInfo.cs b/OpenSim/Framework/Monitoring/Properties/AssemblyInfo.cs index 36678bb..07971bf 100644 --- a/OpenSim/Framework/Monitoring/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Monitoring/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.6.*")] | 32 | [assembly: AssemblyVersion("0.8.0.*")] |
33 | 33 | ||
diff --git a/OpenSim/Framework/Monitoring/ServerStatsCollector.cs b/OpenSim/Framework/Monitoring/ServerStatsCollector.cs new file mode 100644 index 0000000..ac0f0bc --- /dev/null +++ b/OpenSim/Framework/Monitoring/ServerStatsCollector.cs | |||
@@ -0,0 +1,349 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Linq; | ||
32 | using System.Net.NetworkInformation; | ||
33 | using System.Text; | ||
34 | using System.Threading; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | |||
40 | namespace OpenSim.Framework.Monitoring | ||
41 | { | ||
42 | public class ServerStatsCollector | ||
43 | { | ||
44 | private readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | private readonly string LogHeader = "[SERVER STATS]"; | ||
46 | |||
47 | public bool Enabled = false; | ||
48 | private static Dictionary<string, Stat> RegisteredStats = new Dictionary<string, Stat>(); | ||
49 | |||
50 | public readonly string CategoryServer = "server"; | ||
51 | |||
52 | public readonly string ContainerThreadpool = "threadpool"; | ||
53 | public readonly string ContainerProcessor = "processor"; | ||
54 | public readonly string ContainerMemory = "memory"; | ||
55 | public readonly string ContainerNetwork = "network"; | ||
56 | public readonly string ContainerProcess = "process"; | ||
57 | |||
58 | public string NetworkInterfaceTypes = "Ethernet"; | ||
59 | |||
60 | readonly int performanceCounterSampleInterval = 500; | ||
61 | // int lastperformanceCounterSampleTime = 0; | ||
62 | |||
63 | private class PerfCounterControl | ||
64 | { | ||
65 | public PerformanceCounter perfCounter; | ||
66 | public int lastFetch; | ||
67 | public string name; | ||
68 | public PerfCounterControl(PerformanceCounter pPc) | ||
69 | : this(pPc, String.Empty) | ||
70 | { | ||
71 | } | ||
72 | public PerfCounterControl(PerformanceCounter pPc, string pName) | ||
73 | { | ||
74 | perfCounter = pPc; | ||
75 | lastFetch = 0; | ||
76 | name = pName; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | PerfCounterControl processorPercentPerfCounter = null; | ||
81 | |||
82 | // IRegionModuleBase.Initialize | ||
83 | public void Initialise(IConfigSource source) | ||
84 | { | ||
85 | IConfig cfg = source.Configs["Monitoring"]; | ||
86 | |||
87 | if (cfg != null) | ||
88 | Enabled = cfg.GetBoolean("ServerStatsEnabled", true); | ||
89 | |||
90 | if (Enabled) | ||
91 | { | ||
92 | NetworkInterfaceTypes = cfg.GetString("NetworkInterfaceTypes", "Ethernet"); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public void Start() | ||
97 | { | ||
98 | if (RegisteredStats.Count == 0) | ||
99 | RegisterServerStats(); | ||
100 | } | ||
101 | |||
102 | public void Close() | ||
103 | { | ||
104 | if (RegisteredStats.Count > 0) | ||
105 | { | ||
106 | foreach (Stat stat in RegisteredStats.Values) | ||
107 | { | ||
108 | StatsManager.DeregisterStat(stat); | ||
109 | stat.Dispose(); | ||
110 | } | ||
111 | RegisteredStats.Clear(); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private void MakeStat(string pName, string pDesc, string pUnit, string pContainer, Action<Stat> act) | ||
116 | { | ||
117 | MakeStat(pName, pDesc, pUnit, pContainer, act, MeasuresOfInterest.None); | ||
118 | } | ||
119 | |||
120 | private void MakeStat(string pName, string pDesc, string pUnit, string pContainer, Action<Stat> act, MeasuresOfInterest moi) | ||
121 | { | ||
122 | string desc = pDesc; | ||
123 | if (desc == null) | ||
124 | desc = pName; | ||
125 | Stat stat = new Stat(pName, pName, desc, pUnit, CategoryServer, pContainer, StatType.Pull, moi, act, StatVerbosity.Debug); | ||
126 | StatsManager.RegisterStat(stat); | ||
127 | RegisteredStats.Add(pName, stat); | ||
128 | } | ||
129 | |||
130 | public void RegisterServerStats() | ||
131 | { | ||
132 | // lastperformanceCounterSampleTime = Util.EnvironmentTickCount(); | ||
133 | PerformanceCounter tempPC; | ||
134 | Stat tempStat; | ||
135 | string tempName; | ||
136 | |||
137 | try | ||
138 | { | ||
139 | tempName = "CPUPercent"; | ||
140 | tempPC = new PerformanceCounter("Processor", "% Processor Time", "_Total"); | ||
141 | processorPercentPerfCounter = new PerfCounterControl(tempPC); | ||
142 | // A long time bug in mono is that CPU percent is reported as CPU percent idle. Windows reports CPU percent busy. | ||
143 | tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor, | ||
144 | StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter, Util.IsWindows() ? 1 : -1); }, | ||
145 | StatVerbosity.Info); | ||
146 | StatsManager.RegisterStat(tempStat); | ||
147 | RegisteredStats.Add(tempName, tempStat); | ||
148 | |||
149 | MakeStat("TotalProcessorTime", null, "sec", ContainerProcessor, | ||
150 | (s) => { s.Value = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds; }); | ||
151 | |||
152 | MakeStat("UserProcessorTime", null, "sec", ContainerProcessor, | ||
153 | (s) => { s.Value = Process.GetCurrentProcess().UserProcessorTime.TotalSeconds; }); | ||
154 | |||
155 | MakeStat("PrivilegedProcessorTime", null, "sec", ContainerProcessor, | ||
156 | (s) => { s.Value = Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds; }); | ||
157 | |||
158 | MakeStat("Threads", null, "threads", ContainerProcessor, | ||
159 | (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; }); | ||
160 | } | ||
161 | catch (Exception e) | ||
162 | { | ||
163 | m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e); | ||
164 | } | ||
165 | |||
166 | MakeStat("BuiltinThreadpoolWorkerThreadsAvailable", null, "threads", ContainerThreadpool, | ||
167 | s => | ||
168 | { | ||
169 | int workerThreads, iocpThreads; | ||
170 | ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); | ||
171 | s.Value = workerThreads; | ||
172 | }); | ||
173 | |||
174 | MakeStat("BuiltinThreadpoolIOCPThreadsAvailable", null, "threads", ContainerThreadpool, | ||
175 | s => | ||
176 | { | ||
177 | int workerThreads, iocpThreads; | ||
178 | ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); | ||
179 | s.Value = iocpThreads; | ||
180 | }); | ||
181 | |||
182 | if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool && Util.GetSmartThreadPoolInfo() != null) | ||
183 | { | ||
184 | MakeStat("STPMaxThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxThreads); | ||
185 | MakeStat("STPMinThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MinThreads); | ||
186 | MakeStat("STPConcurrency", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxConcurrentWorkItems); | ||
187 | MakeStat("STPActiveThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().ActiveThreads); | ||
188 | MakeStat("STPInUseThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().InUseThreads); | ||
189 | MakeStat("STPWorkItemsWaiting", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().WaitingCallbacks); | ||
190 | } | ||
191 | |||
192 | MakeStat( | ||
193 | "HTTPRequestsMade", | ||
194 | "Number of outbound HTTP requests made", | ||
195 | "requests", | ||
196 | ContainerNetwork, | ||
197 | s => s.Value = WebUtil.RequestNumber, | ||
198 | MeasuresOfInterest.AverageChangeOverTime); | ||
199 | |||
200 | try | ||
201 | { | ||
202 | List<string> okInterfaceTypes = new List<string>(NetworkInterfaceTypes.Split(',')); | ||
203 | |||
204 | IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces(); | ||
205 | foreach (NetworkInterface nic in nics) | ||
206 | { | ||
207 | if (nic.OperationalStatus != OperationalStatus.Up) | ||
208 | continue; | ||
209 | |||
210 | string nicInterfaceType = nic.NetworkInterfaceType.ToString(); | ||
211 | if (!okInterfaceTypes.Contains(nicInterfaceType)) | ||
212 | { | ||
213 | m_log.DebugFormat("{0} Not including stats for network interface '{1}' of type '{2}'.", | ||
214 | LogHeader, nic.Name, nicInterfaceType); | ||
215 | m_log.DebugFormat("{0} To include, add to comma separated list in [Monitoring]NetworkInterfaceTypes={1}", | ||
216 | LogHeader, NetworkInterfaceTypes); | ||
217 | continue; | ||
218 | } | ||
219 | |||
220 | if (nic.Supports(NetworkInterfaceComponent.IPv4)) | ||
221 | { | ||
222 | IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics(); | ||
223 | if (nicStats != null) | ||
224 | { | ||
225 | MakeStat("BytesRcvd/" + nic.Name, nic.Name, "KB", ContainerNetwork, | ||
226 | (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); }); | ||
227 | MakeStat("BytesSent/" + nic.Name, nic.Name, "KB", ContainerNetwork, | ||
228 | (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); }); | ||
229 | MakeStat("TotalBytes/" + nic.Name, nic.Name, "KB", ContainerNetwork, | ||
230 | (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); }); | ||
231 | } | ||
232 | } | ||
233 | // TODO: add IPv6 (it may actually happen someday) | ||
234 | } | ||
235 | } | ||
236 | catch (Exception e) | ||
237 | { | ||
238 | m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e); | ||
239 | } | ||
240 | |||
241 | MakeStat("ProcessMemory", null, "MB", ContainerMemory, | ||
242 | (s) => { s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d, 3); }); | ||
243 | MakeStat("HeapMemory", null, "MB", ContainerMemory, | ||
244 | (s) => { s.Value = Math.Round(GC.GetTotalMemory(false) / 1024d / 1024d, 3); }); | ||
245 | MakeStat("LastHeapAllocationRate", null, "MB/sec", ContainerMemory, | ||
246 | (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); }); | ||
247 | MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory, | ||
248 | (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); }); | ||
249 | } | ||
250 | |||
251 | // Notes on performance counters: | ||
252 | // "How To Read Performance Counters": http://blogs.msdn.com/b/bclteam/archive/2006/06/02/618156.aspx | ||
253 | // "How to get the CPU Usage in C#": http://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c | ||
254 | // "Mono Performance Counters": http://www.mono-project.com/Mono_Performance_Counters | ||
255 | private delegate double PerfCounterNextValue(); | ||
256 | private void GetNextValue(Stat stat, PerfCounterControl perfControl) | ||
257 | { | ||
258 | GetNextValue(stat, perfControl, 1.0); | ||
259 | } | ||
260 | private void GetNextValue(Stat stat, PerfCounterControl perfControl, double factor) | ||
261 | { | ||
262 | if (Util.EnvironmentTickCountSubtract(perfControl.lastFetch) > performanceCounterSampleInterval) | ||
263 | { | ||
264 | if (perfControl != null && perfControl.perfCounter != null) | ||
265 | { | ||
266 | try | ||
267 | { | ||
268 | // Kludge for factor to run double duty. If -1, subtract the value from one | ||
269 | if (factor == -1) | ||
270 | stat.Value = 1 - perfControl.perfCounter.NextValue(); | ||
271 | else | ||
272 | stat.Value = perfControl.perfCounter.NextValue() / factor; | ||
273 | } | ||
274 | catch (Exception e) | ||
275 | { | ||
276 | m_log.ErrorFormat("{0} Exception on NextValue fetching {1}: {2}", LogHeader, stat.Name, e); | ||
277 | } | ||
278 | perfControl.lastFetch = Util.EnvironmentTickCount(); | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | // Lookup the nic that goes with this stat and set the value by using a fetch action. | ||
284 | // Not sure about closure with delegates inside delegates. | ||
285 | private delegate double GetIPv4StatValue(IPv4InterfaceStatistics interfaceStat); | ||
286 | private void LookupNic(Stat stat, GetIPv4StatValue getter, double factor) | ||
287 | { | ||
288 | // Get the one nic that has the name of this stat | ||
289 | IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where( | ||
290 | (network) => network.Name == stat.Description); | ||
291 | try | ||
292 | { | ||
293 | foreach (NetworkInterface nic in nics) | ||
294 | { | ||
295 | IPv4InterfaceStatistics intrStats = nic.GetIPv4Statistics(); | ||
296 | if (intrStats != null) | ||
297 | { | ||
298 | double newVal = Math.Round(getter(intrStats) / factor, 3); | ||
299 | stat.Value = newVal; | ||
300 | } | ||
301 | break; | ||
302 | } | ||
303 | } | ||
304 | catch | ||
305 | { | ||
306 | // There are times interfaces go away so we just won't update the stat for this | ||
307 | m_log.ErrorFormat("{0} Exception fetching stat on interface '{1}'", LogHeader, stat.Description); | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | |||
312 | public class ServerStatsAggregator : Stat | ||
313 | { | ||
314 | public ServerStatsAggregator( | ||
315 | string shortName, | ||
316 | string name, | ||
317 | string description, | ||
318 | string unitName, | ||
319 | string category, | ||
320 | string container | ||
321 | ) | ||
322 | : base( | ||
323 | shortName, | ||
324 | name, | ||
325 | description, | ||
326 | unitName, | ||
327 | category, | ||
328 | container, | ||
329 | StatType.Push, | ||
330 | MeasuresOfInterest.None, | ||
331 | null, | ||
332 | StatVerbosity.Info) | ||
333 | { | ||
334 | } | ||
335 | public override string ToConsoleString() | ||
336 | { | ||
337 | StringBuilder sb = new StringBuilder(); | ||
338 | |||
339 | return sb.ToString(); | ||
340 | } | ||
341 | |||
342 | public override OSDMap ToOSDMap() | ||
343 | { | ||
344 | OSDMap ret = new OSDMap(); | ||
345 | |||
346 | return ret; | ||
347 | } | ||
348 | } | ||
349 | } | ||
diff --git a/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs b/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs index 6a68322..f6f458d 100644 --- a/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs +++ b/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
30 | using System.Text; | 31 | using System.Text; |
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
32 | using OpenMetaverse.StructuredData; | 33 | using OpenMetaverse.StructuredData; |
@@ -39,8 +40,6 @@ namespace OpenSim.Framework.Monitoring | |||
39 | /// </summary> | 40 | /// </summary> |
40 | public class SimExtraStatsCollector : BaseStatsCollector | 41 | public class SimExtraStatsCollector : BaseStatsCollector |
41 | { | 42 | { |
42 | private long abnormalClientThreadTerminations; | ||
43 | |||
44 | // private long assetsInCache; | 43 | // private long assetsInCache; |
45 | // private long texturesInCache; | 44 | // private long texturesInCache; |
46 | // private long assetCacheMemoryUsage; | 45 | // private long assetCacheMemoryUsage; |
@@ -73,11 +72,6 @@ namespace OpenSim.Framework.Monitoring | |||
73 | private volatile float activeScripts; | 72 | private volatile float activeScripts; |
74 | private volatile float scriptLinesPerSecond; | 73 | private volatile float scriptLinesPerSecond; |
75 | 74 | ||
76 | /// <summary> | ||
77 | /// Number of times that a client thread terminated because of an exception | ||
78 | /// </summary> | ||
79 | public long AbnormalClientThreadTerminations { get { return abnormalClientThreadTerminations; } } | ||
80 | |||
81 | // /// <summary> | 75 | // /// <summary> |
82 | // /// These statistics are being collected by push rather than pull. Pull would be simpler, but I had the | 76 | // /// These statistics are being collected by push rather than pull. Pull would be simpler, but I had the |
83 | // /// notion of providing some flow statistics (which pull wouldn't give us). Though admittedly these | 77 | // /// notion of providing some flow statistics (which pull wouldn't give us). Though admittedly these |
@@ -166,11 +160,6 @@ namespace OpenSim.Framework.Monitoring | |||
166 | private IDictionary<UUID, PacketQueueStatsCollector> packetQueueStatsCollectors | 160 | private IDictionary<UUID, PacketQueueStatsCollector> packetQueueStatsCollectors |
167 | = new Dictionary<UUID, PacketQueueStatsCollector>(); | 161 | = new Dictionary<UUID, PacketQueueStatsCollector>(); |
168 | 162 | ||
169 | public void AddAbnormalClientThreadTermination() | ||
170 | { | ||
171 | abnormalClientThreadTerminations++; | ||
172 | } | ||
173 | |||
174 | // public void AddAsset(AssetBase asset) | 163 | // public void AddAsset(AssetBase asset) |
175 | // { | 164 | // { |
176 | // assetsInCache++; | 165 | // assetsInCache++; |
@@ -324,10 +313,12 @@ Asset service request failures: {3}" + Environment.NewLine, | |||
324 | sb.Append(Environment.NewLine); | 313 | sb.Append(Environment.NewLine); |
325 | sb.Append("CONNECTION STATISTICS"); | 314 | sb.Append("CONNECTION STATISTICS"); |
326 | sb.Append(Environment.NewLine); | 315 | sb.Append(Environment.NewLine); |
327 | sb.Append( | 316 | |
328 | string.Format( | 317 | List<Stat> stats = StatsManager.GetStatsFromEachContainer("clientstack", "ClientLogoutsDueToNoReceives"); |
329 | "Abnormal client thread terminations: {0}" + Environment.NewLine, | 318 | |
330 | abnormalClientThreadTerminations)); | 319 | sb.AppendFormat( |
320 | "Client logouts due to no data receive timeout: {0}\n\n", | ||
321 | stats != null ? stats.Sum(s => s.Value).ToString() : "unknown"); | ||
331 | 322 | ||
332 | // sb.Append(Environment.NewLine); | 323 | // sb.Append(Environment.NewLine); |
333 | // sb.Append("INVENTORY STATISTICS"); | 324 | // sb.Append("INVENTORY STATISTICS"); |
@@ -338,7 +329,7 @@ Asset service request failures: {3}" + Environment.NewLine, | |||
338 | // InventoryServiceRetrievalFailures)); | 329 | // InventoryServiceRetrievalFailures)); |
339 | 330 | ||
340 | sb.Append(Environment.NewLine); | 331 | sb.Append(Environment.NewLine); |
341 | sb.Append("FRAME STATISTICS"); | 332 | sb.Append("SAMPLE FRAME STATISTICS"); |
342 | sb.Append(Environment.NewLine); | 333 | sb.Append(Environment.NewLine); |
343 | sb.Append("Dilatn SimFPS PhyFPS AgntUp RootAg ChldAg Prims AtvPrm AtvScr ScrLPS"); | 334 | sb.Append("Dilatn SimFPS PhyFPS AgntUp RootAg ChldAg Prims AtvPrm AtvScr ScrLPS"); |
344 | sb.Append(Environment.NewLine); | 335 | sb.Append(Environment.NewLine); |
diff --git a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs index caea30d..318cf1c 100755 --- a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs +++ b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs | |||
@@ -34,142 +34,6 @@ using OpenMetaverse.StructuredData; | |||
34 | 34 | ||
35 | namespace OpenSim.Framework.Monitoring | 35 | namespace OpenSim.Framework.Monitoring |
36 | { | 36 | { |
37 | // Create a time histogram of events. The histogram is built in a wrap-around | ||
38 | // array of equally distributed buckets. | ||
39 | // For instance, a minute long histogram of second sized buckets would be: | ||
40 | // new EventHistogram(60, 1000) | ||
41 | public class EventHistogram | ||
42 | { | ||
43 | private int m_timeBase; | ||
44 | private int m_numBuckets; | ||
45 | private int m_bucketMilliseconds; | ||
46 | private int m_lastBucket; | ||
47 | private int m_totalHistogramMilliseconds; | ||
48 | private long[] m_histogram; | ||
49 | private object histoLock = new object(); | ||
50 | |||
51 | public EventHistogram(int numberOfBuckets, int millisecondsPerBucket) | ||
52 | { | ||
53 | m_numBuckets = numberOfBuckets; | ||
54 | m_bucketMilliseconds = millisecondsPerBucket; | ||
55 | m_totalHistogramMilliseconds = m_numBuckets * m_bucketMilliseconds; | ||
56 | |||
57 | m_histogram = new long[m_numBuckets]; | ||
58 | Zero(); | ||
59 | m_lastBucket = 0; | ||
60 | m_timeBase = Util.EnvironmentTickCount(); | ||
61 | } | ||
62 | |||
63 | public void Event() | ||
64 | { | ||
65 | this.Event(1); | ||
66 | } | ||
67 | |||
68 | // Record an event at time 'now' in the histogram. | ||
69 | public void Event(int cnt) | ||
70 | { | ||
71 | lock (histoLock) | ||
72 | { | ||
73 | // The time as displaced from the base of the histogram | ||
74 | int bucketTime = Util.EnvironmentTickCountSubtract(m_timeBase); | ||
75 | |||
76 | // If more than the total time of the histogram, we just start over | ||
77 | if (bucketTime > m_totalHistogramMilliseconds) | ||
78 | { | ||
79 | Zero(); | ||
80 | m_lastBucket = 0; | ||
81 | m_timeBase = Util.EnvironmentTickCount(); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | // To which bucket should we add this event? | ||
86 | int bucket = bucketTime / m_bucketMilliseconds; | ||
87 | |||
88 | // Advance m_lastBucket to the new bucket. Zero any buckets skipped over. | ||
89 | while (bucket != m_lastBucket) | ||
90 | { | ||
91 | // Zero from just after the last bucket to the new bucket or the end | ||
92 | for (int jj = m_lastBucket + 1; jj <= Math.Min(bucket, m_numBuckets - 1); jj++) | ||
93 | { | ||
94 | m_histogram[jj] = 0; | ||
95 | } | ||
96 | m_lastBucket = bucket; | ||
97 | // If the new bucket is off the end, wrap around to the beginning | ||
98 | if (bucket > m_numBuckets) | ||
99 | { | ||
100 | bucket -= m_numBuckets; | ||
101 | m_lastBucket = 0; | ||
102 | m_histogram[m_lastBucket] = 0; | ||
103 | m_timeBase += m_totalHistogramMilliseconds; | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | m_histogram[m_lastBucket] += cnt; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | // Get a copy of the current histogram | ||
112 | public long[] GetHistogram() | ||
113 | { | ||
114 | long[] ret = new long[m_numBuckets]; | ||
115 | lock (histoLock) | ||
116 | { | ||
117 | int indx = m_lastBucket + 1; | ||
118 | for (int ii = 0; ii < m_numBuckets; ii++, indx++) | ||
119 | { | ||
120 | if (indx >= m_numBuckets) | ||
121 | indx = 0; | ||
122 | ret[ii] = m_histogram[indx]; | ||
123 | } | ||
124 | } | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | public OSDMap GetHistogramAsOSDMap() | ||
129 | { | ||
130 | OSDMap ret = new OSDMap(); | ||
131 | |||
132 | ret.Add("Buckets", OSD.FromInteger(m_numBuckets)); | ||
133 | ret.Add("BucketMilliseconds", OSD.FromInteger(m_bucketMilliseconds)); | ||
134 | ret.Add("TotalMilliseconds", OSD.FromInteger(m_totalHistogramMilliseconds)); | ||
135 | |||
136 | // Compute a number for the first bucket in the histogram. | ||
137 | // This will allow readers to know how this histogram relates to any previously read histogram. | ||
138 | int baseBucketNum = (m_timeBase / m_bucketMilliseconds) + m_lastBucket + 1; | ||
139 | ret.Add("BaseNumber", OSD.FromInteger(baseBucketNum)); | ||
140 | |||
141 | ret.Add("Values", GetHistogramAsOSDArray()); | ||
142 | |||
143 | return ret; | ||
144 | } | ||
145 | // Get a copy of the current histogram | ||
146 | public OSDArray GetHistogramAsOSDArray() | ||
147 | { | ||
148 | OSDArray ret = new OSDArray(m_numBuckets); | ||
149 | lock (histoLock) | ||
150 | { | ||
151 | int indx = m_lastBucket + 1; | ||
152 | for (int ii = 0; ii < m_numBuckets; ii++, indx++) | ||
153 | { | ||
154 | if (indx >= m_numBuckets) | ||
155 | indx = 0; | ||
156 | ret[ii] = OSD.FromLong(m_histogram[indx]); | ||
157 | } | ||
158 | } | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | // Zero out the histogram | ||
163 | public void Zero() | ||
164 | { | ||
165 | lock (histoLock) | ||
166 | { | ||
167 | for (int ii = 0; ii < m_numBuckets; ii++) | ||
168 | m_histogram[ii] = 0; | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | |||
173 | // A statistic that wraps a counter. | 37 | // A statistic that wraps a counter. |
174 | // Built this way mostly so histograms and history can be created. | 38 | // Built this way mostly so histograms and history can be created. |
175 | public class CounterStat : Stat | 39 | public class CounterStat : Stat |
@@ -224,5 +88,32 @@ public class CounterStat : Stat | |||
224 | } | 88 | } |
225 | } | 89 | } |
226 | } | 90 | } |
91 | |||
92 | // CounterStat is a basic stat plus histograms | ||
93 | public override OSDMap ToOSDMap() | ||
94 | { | ||
95 | // Get the foundational instance | ||
96 | OSDMap map = base.ToOSDMap(); | ||
97 | |||
98 | map["StatType"] = "CounterStat"; | ||
99 | |||
100 | // If there are any histograms, add a new field that is an array of histograms as OSDMaps | ||
101 | if (m_histograms.Count > 0) | ||
102 | { | ||
103 | lock (counterLock) | ||
104 | { | ||
105 | if (m_histograms.Count > 0) | ||
106 | { | ||
107 | OSDArray histos = new OSDArray(); | ||
108 | foreach (EventHistogram histo in m_histograms.Values) | ||
109 | { | ||
110 | histos.Add(histo.GetHistogramAsOSDMap()); | ||
111 | } | ||
112 | map.Add("Histograms", histos); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | return map; | ||
117 | } | ||
227 | } | 118 | } |
228 | } | 119 | } |
diff --git a/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs b/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs new file mode 100755 index 0000000..f51f322 --- /dev/null +++ b/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs | |||
@@ -0,0 +1,173 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenMetaverse.StructuredData; | ||
34 | |||
35 | namespace OpenSim.Framework.Monitoring | ||
36 | { | ||
37 | // Create a time histogram of events. The histogram is built in a wrap-around | ||
38 | // array of equally distributed buckets. | ||
39 | // For instance, a minute long histogram of second sized buckets would be: | ||
40 | // new EventHistogram(60, 1000) | ||
41 | public class EventHistogram | ||
42 | { | ||
43 | private int m_timeBase; | ||
44 | private int m_numBuckets; | ||
45 | private int m_bucketMilliseconds; | ||
46 | private int m_lastBucket; | ||
47 | private int m_totalHistogramMilliseconds; | ||
48 | private long[] m_histogram; | ||
49 | private object histoLock = new object(); | ||
50 | |||
51 | public EventHistogram(int numberOfBuckets, int millisecondsPerBucket) | ||
52 | { | ||
53 | m_numBuckets = numberOfBuckets; | ||
54 | m_bucketMilliseconds = millisecondsPerBucket; | ||
55 | m_totalHistogramMilliseconds = m_numBuckets * m_bucketMilliseconds; | ||
56 | |||
57 | m_histogram = new long[m_numBuckets]; | ||
58 | Zero(); | ||
59 | m_lastBucket = 0; | ||
60 | m_timeBase = Util.EnvironmentTickCount(); | ||
61 | } | ||
62 | |||
63 | public void Event() | ||
64 | { | ||
65 | this.Event(1); | ||
66 | } | ||
67 | |||
68 | // Record an event at time 'now' in the histogram. | ||
69 | public void Event(int cnt) | ||
70 | { | ||
71 | lock (histoLock) | ||
72 | { | ||
73 | // The time as displaced from the base of the histogram | ||
74 | int bucketTime = Util.EnvironmentTickCountSubtract(m_timeBase); | ||
75 | |||
76 | // If more than the total time of the histogram, we just start over | ||
77 | if (bucketTime > m_totalHistogramMilliseconds) | ||
78 | { | ||
79 | Zero(); | ||
80 | m_lastBucket = 0; | ||
81 | m_timeBase = Util.EnvironmentTickCount(); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | // To which bucket should we add this event? | ||
86 | int bucket = bucketTime / m_bucketMilliseconds; | ||
87 | |||
88 | // Advance m_lastBucket to the new bucket. Zero any buckets skipped over. | ||
89 | while (bucket != m_lastBucket) | ||
90 | { | ||
91 | // Zero from just after the last bucket to the new bucket or the end | ||
92 | for (int jj = m_lastBucket + 1; jj <= Math.Min(bucket, m_numBuckets - 1); jj++) | ||
93 | { | ||
94 | m_histogram[jj] = 0; | ||
95 | } | ||
96 | m_lastBucket = bucket; | ||
97 | // If the new bucket is off the end, wrap around to the beginning | ||
98 | if (bucket > m_numBuckets) | ||
99 | { | ||
100 | bucket -= m_numBuckets; | ||
101 | m_lastBucket = 0; | ||
102 | m_histogram[m_lastBucket] = 0; | ||
103 | m_timeBase += m_totalHistogramMilliseconds; | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | m_histogram[m_lastBucket] += cnt; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | // Get a copy of the current histogram | ||
112 | public long[] GetHistogram() | ||
113 | { | ||
114 | long[] ret = new long[m_numBuckets]; | ||
115 | lock (histoLock) | ||
116 | { | ||
117 | int indx = m_lastBucket + 1; | ||
118 | for (int ii = 0; ii < m_numBuckets; ii++, indx++) | ||
119 | { | ||
120 | if (indx >= m_numBuckets) | ||
121 | indx = 0; | ||
122 | ret[ii] = m_histogram[indx]; | ||
123 | } | ||
124 | } | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | public OSDMap GetHistogramAsOSDMap() | ||
129 | { | ||
130 | OSDMap ret = new OSDMap(); | ||
131 | |||
132 | ret.Add("Buckets", OSD.FromInteger(m_numBuckets)); | ||
133 | ret.Add("BucketMilliseconds", OSD.FromInteger(m_bucketMilliseconds)); | ||
134 | ret.Add("TotalMilliseconds", OSD.FromInteger(m_totalHistogramMilliseconds)); | ||
135 | |||
136 | // Compute a number for the first bucket in the histogram. | ||
137 | // This will allow readers to know how this histogram relates to any previously read histogram. | ||
138 | int baseBucketNum = (m_timeBase / m_bucketMilliseconds) + m_lastBucket + 1; | ||
139 | ret.Add("BaseNumber", OSD.FromInteger(baseBucketNum)); | ||
140 | |||
141 | ret.Add("Values", GetHistogramAsOSDArray()); | ||
142 | |||
143 | return ret; | ||
144 | } | ||
145 | // Get a copy of the current histogram | ||
146 | public OSDArray GetHistogramAsOSDArray() | ||
147 | { | ||
148 | OSDArray ret = new OSDArray(m_numBuckets); | ||
149 | lock (histoLock) | ||
150 | { | ||
151 | int indx = m_lastBucket + 1; | ||
152 | for (int ii = 0; ii < m_numBuckets; ii++, indx++) | ||
153 | { | ||
154 | if (indx >= m_numBuckets) | ||
155 | indx = 0; | ||
156 | ret[ii] = OSD.FromLong(m_histogram[indx]); | ||
157 | } | ||
158 | } | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | // Zero out the histogram | ||
163 | public void Zero() | ||
164 | { | ||
165 | lock (histoLock) | ||
166 | { | ||
167 | for (int ii = 0; ii < m_numBuckets; ii++) | ||
168 | m_histogram[ii] = 0; | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | |||
173 | } | ||
diff --git a/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs b/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs index 60bed55..55ddf06 100644 --- a/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs +++ b/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs | |||
@@ -29,6 +29,8 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | 30 | using System.Text; |
31 | 31 | ||
32 | using OpenMetaverse.StructuredData; | ||
33 | |||
32 | namespace OpenSim.Framework.Monitoring | 34 | namespace OpenSim.Framework.Monitoring |
33 | { | 35 | { |
34 | public class PercentageStat : Stat | 36 | public class PercentageStat : Stat |
@@ -84,5 +86,19 @@ namespace OpenSim.Framework.Monitoring | |||
84 | 86 | ||
85 | return sb.ToString(); | 87 | return sb.ToString(); |
86 | } | 88 | } |
89 | |||
90 | // PercentageStat is a basic stat plus percent calc | ||
91 | public override OSDMap ToOSDMap() | ||
92 | { | ||
93 | // Get the foundational instance | ||
94 | OSDMap map = base.ToOSDMap(); | ||
95 | |||
96 | map["StatType"] = "PercentageStat"; | ||
97 | |||
98 | map.Add("Antecedent", OSD.FromLong(Antecedent)); | ||
99 | map.Add("Consequent", OSD.FromLong(Consequent)); | ||
100 | |||
101 | return map; | ||
102 | } | ||
87 | } | 103 | } |
88 | } \ No newline at end of file | 104 | } \ No newline at end of file |
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs index 2e7665f..e095801 100644 --- a/OpenSim/Framework/Monitoring/Stats/Stat.cs +++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs | |||
@@ -27,8 +27,10 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
30 | using System.Text; | 32 | using System.Text; |
31 | 33 | using log4net; | |
32 | using OpenMetaverse.StructuredData; | 34 | using OpenMetaverse.StructuredData; |
33 | 35 | ||
34 | namespace OpenSim.Framework.Monitoring | 36 | namespace OpenSim.Framework.Monitoring |
@@ -38,6 +40,10 @@ namespace OpenSim.Framework.Monitoring | |||
38 | /// </summary> | 40 | /// </summary> |
39 | public class Stat : IDisposable | 41 | public class Stat : IDisposable |
40 | { | 42 | { |
43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | public static readonly char[] DisallowedShortNameCharacters = { '.' }; | ||
46 | |||
41 | /// <summary> | 47 | /// <summary> |
42 | /// Category of this stat (e.g. cache, scene, etc). | 48 | /// Category of this stat (e.g. cache, scene, etc). |
43 | /// </summary> | 49 | /// </summary> |
@@ -95,7 +101,7 @@ namespace OpenSim.Framework.Monitoring | |||
95 | /// <remarks> | 101 | /// <remarks> |
96 | /// Will be null if no measures of interest require samples. | 102 | /// Will be null if no measures of interest require samples. |
97 | /// </remarks> | 103 | /// </remarks> |
98 | private static Queue<double> m_samples; | 104 | private Queue<double> m_samples; |
99 | 105 | ||
100 | /// <summary> | 106 | /// <summary> |
101 | /// Maximum number of statistical samples. | 107 | /// Maximum number of statistical samples. |
@@ -162,6 +168,12 @@ namespace OpenSim.Framework.Monitoring | |||
162 | throw new Exception( | 168 | throw new Exception( |
163 | string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); | 169 | string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); |
164 | 170 | ||
171 | foreach (char c in DisallowedShortNameCharacters) | ||
172 | { | ||
173 | if (shortName.IndexOf(c) != -1) | ||
174 | throw new Exception(string.Format("Stat name {0} cannot contain character {1}", shortName, c)); | ||
175 | } | ||
176 | |||
165 | ShortName = shortName; | 177 | ShortName = shortName; |
166 | Name = name; | 178 | Name = name; |
167 | Description = description; | 179 | Description = description; |
@@ -204,6 +216,8 @@ namespace OpenSim.Framework.Monitoring | |||
204 | if (m_samples.Count >= m_maxSamples) | 216 | if (m_samples.Count >= m_maxSamples) |
205 | m_samples.Dequeue(); | 217 | m_samples.Dequeue(); |
206 | 218 | ||
219 | // m_log.DebugFormat("[STAT]: Recording value {0} for {1}", newValue, Name); | ||
220 | |||
207 | m_samples.Enqueue(newValue); | 221 | m_samples.Enqueue(newValue); |
208 | } | 222 | } |
209 | } | 223 | } |
@@ -211,7 +225,13 @@ namespace OpenSim.Framework.Monitoring | |||
211 | public virtual string ToConsoleString() | 225 | public virtual string ToConsoleString() |
212 | { | 226 | { |
213 | StringBuilder sb = new StringBuilder(); | 227 | StringBuilder sb = new StringBuilder(); |
214 | sb.AppendFormat("{0}.{1}.{2} : {3} {4}", Category, Container, ShortName, Value, UnitName); | 228 | sb.AppendFormat( |
229 | "{0}.{1}.{2} : {3}{4}", | ||
230 | Category, | ||
231 | Container, | ||
232 | ShortName, | ||
233 | Value, | ||
234 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName)); | ||
215 | 235 | ||
216 | AppendMeasuresOfInterest(sb); | 236 | AppendMeasuresOfInterest(sb); |
217 | 237 | ||
@@ -221,6 +241,8 @@ namespace OpenSim.Framework.Monitoring | |||
221 | public virtual OSDMap ToOSDMap() | 241 | public virtual OSDMap ToOSDMap() |
222 | { | 242 | { |
223 | OSDMap ret = new OSDMap(); | 243 | OSDMap ret = new OSDMap(); |
244 | ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat | ||
245 | |||
224 | ret.Add("Category", OSD.FromString(Category)); | 246 | ret.Add("Category", OSD.FromString(Category)); |
225 | ret.Add("Container", OSD.FromString(Container)); | 247 | ret.Add("Container", OSD.FromString(Container)); |
226 | ret.Add("ShortName", OSD.FromString(ShortName)); | 248 | ret.Add("ShortName", OSD.FromString(ShortName)); |
@@ -229,31 +251,74 @@ namespace OpenSim.Framework.Monitoring | |||
229 | ret.Add("UnitName", OSD.FromString(UnitName)); | 251 | ret.Add("UnitName", OSD.FromString(UnitName)); |
230 | ret.Add("Value", OSD.FromReal(Value)); | 252 | ret.Add("Value", OSD.FromReal(Value)); |
231 | 253 | ||
254 | double lastChangeOverTime, averageChangeOverTime; | ||
255 | if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime)) | ||
256 | { | ||
257 | ret.Add("LastChangeOverTime", OSD.FromReal(lastChangeOverTime)); | ||
258 | ret.Add("AverageChangeOverTime", OSD.FromReal(averageChangeOverTime)); | ||
259 | } | ||
260 | |||
232 | return ret; | 261 | return ret; |
233 | } | 262 | } |
234 | 263 | ||
235 | protected void AppendMeasuresOfInterest(StringBuilder sb) | 264 | // Compute the averages over time and return same. |
265 | // Return 'true' if averages were actually computed. 'false' if no average info. | ||
266 | public bool ComputeMeasuresOfInterest(out double lastChangeOverTime, out double averageChangeOverTime) | ||
236 | { | 267 | { |
237 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) | 268 | bool ret = false; |
238 | == MeasuresOfInterest.AverageChangeOverTime) | 269 | lastChangeOverTime = 0; |
270 | averageChangeOverTime = 0; | ||
271 | |||
272 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime) | ||
239 | { | 273 | { |
240 | double totalChange = 0; | 274 | double totalChange = 0; |
275 | double? penultimateSample = null; | ||
241 | double? lastSample = null; | 276 | double? lastSample = null; |
242 | 277 | ||
243 | lock (m_samples) | 278 | lock (m_samples) |
244 | { | 279 | { |
280 | // m_log.DebugFormat( | ||
281 | // "[STAT]: Samples for {0} are {1}", | ||
282 | // Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray())); | ||
283 | |||
245 | foreach (double s in m_samples) | 284 | foreach (double s in m_samples) |
246 | { | 285 | { |
247 | if (lastSample != null) | 286 | if (lastSample != null) |
248 | totalChange += s - (double)lastSample; | 287 | totalChange += s - (double)lastSample; |
249 | 288 | ||
289 | penultimateSample = lastSample; | ||
250 | lastSample = s; | 290 | lastSample = s; |
251 | } | 291 | } |
252 | } | 292 | } |
253 | 293 | ||
294 | if (lastSample != null && penultimateSample != null) | ||
295 | { | ||
296 | lastChangeOverTime | ||
297 | = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); | ||
298 | } | ||
299 | |||
254 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; | 300 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; |
255 | 301 | ||
256 | sb.AppendFormat(", {0:0.##}{1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName); | 302 | averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); |
303 | ret = true; | ||
304 | } | ||
305 | |||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | protected void AppendMeasuresOfInterest(StringBuilder sb) | ||
310 | { | ||
311 | double lastChangeOverTime = 0; | ||
312 | double averageChangeOverTime = 0; | ||
313 | |||
314 | if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime)) | ||
315 | { | ||
316 | sb.AppendFormat( | ||
317 | ", {0:0.##}{1}/s, {2:0.##}{3}/s", | ||
318 | lastChangeOverTime, | ||
319 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName), | ||
320 | averageChangeOverTime, | ||
321 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName)); | ||
257 | } | 322 | } |
258 | } | 323 | } |
259 | } | 324 | } |
diff --git a/OpenSim/Framework/Monitoring/StatsLogger.cs b/OpenSim/Framework/Monitoring/StatsLogger.cs new file mode 100644 index 0000000..1e4fa11 --- /dev/null +++ b/OpenSim/Framework/Monitoring/StatsLogger.cs | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Timers; | ||
31 | using log4net; | ||
32 | |||
33 | namespace OpenSim.Framework.Monitoring | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Provides a means to continuously log stats for debugging purposes. | ||
37 | /// </summary> | ||
38 | public static class StatsLogger | ||
39 | { | ||
40 | private static readonly ILog m_statsLog = LogManager.GetLogger("special.StatsLogger"); | ||
41 | |||
42 | private static Timer m_loggingTimer; | ||
43 | private static int m_statsLogIntervalMs = 5000; | ||
44 | |||
45 | public static void RegisterConsoleCommands(ICommandConsole console) | ||
46 | { | ||
47 | console.Commands.AddCommand( | ||
48 | "Debug", | ||
49 | false, | ||
50 | "debug stats record", | ||
51 | "debug stats record start|stop", | ||
52 | "Control whether stats are being regularly recorded to a separate file.", | ||
53 | "For debug purposes. Experimental.", | ||
54 | HandleStatsRecordCommand); | ||
55 | } | ||
56 | |||
57 | public static void HandleStatsRecordCommand(string module, string[] cmd) | ||
58 | { | ||
59 | ICommandConsole con = MainConsole.Instance; | ||
60 | |||
61 | if (cmd.Length != 4) | ||
62 | { | ||
63 | con.Output("Usage: debug stats record start|stop"); | ||
64 | return; | ||
65 | } | ||
66 | |||
67 | if (cmd[3] == "start") | ||
68 | { | ||
69 | Start(); | ||
70 | con.OutputFormat("Now recording all stats to file every {0}ms", m_statsLogIntervalMs); | ||
71 | } | ||
72 | else if (cmd[3] == "stop") | ||
73 | { | ||
74 | Stop(); | ||
75 | con.Output("Stopped recording stats to file."); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | public static void Start() | ||
80 | { | ||
81 | if (m_loggingTimer != null) | ||
82 | Stop(); | ||
83 | |||
84 | m_loggingTimer = new Timer(m_statsLogIntervalMs); | ||
85 | m_loggingTimer.AutoReset = false; | ||
86 | m_loggingTimer.Elapsed += Log; | ||
87 | m_loggingTimer.Start(); | ||
88 | } | ||
89 | |||
90 | public static void Stop() | ||
91 | { | ||
92 | if (m_loggingTimer != null) | ||
93 | { | ||
94 | m_loggingTimer.Stop(); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | private static void Log(object sender, ElapsedEventArgs e) | ||
99 | { | ||
100 | m_statsLog.InfoFormat("*** STATS REPORT AT {0} ***", DateTime.Now); | ||
101 | |||
102 | foreach (string report in StatsManager.GetAllStatsReports()) | ||
103 | m_statsLog.Info(report); | ||
104 | |||
105 | m_loggingTimer.Start(); | ||
106 | } | ||
107 | } | ||
108 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs index 24db6d4..05ee4c5 100644 --- a/OpenSim/Framework/Monitoring/StatsManager.cs +++ b/OpenSim/Framework/Monitoring/StatsManager.cs | |||
@@ -26,15 +26,20 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | ||
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Linq; | ||
30 | using System.Text; | 32 | using System.Text; |
31 | 33 | ||
34 | using OpenSim.Framework; | ||
35 | using OpenMetaverse.StructuredData; | ||
36 | |||
32 | namespace OpenSim.Framework.Monitoring | 37 | namespace OpenSim.Framework.Monitoring |
33 | { | 38 | { |
34 | /// <summary> | 39 | /// <summary> |
35 | /// Singleton used to provide access to statistics reporters | 40 | /// Static class used to register/deregister/fetch statistics |
36 | /// </summary> | 41 | /// </summary> |
37 | public class StatsManager | 42 | public static class StatsManager |
38 | { | 43 | { |
39 | // Subcommand used to list other stats. | 44 | // Subcommand used to list other stats. |
40 | public const string AllSubCommand = "all"; | 45 | public const string AllSubCommand = "all"; |
@@ -54,13 +59,13 @@ namespace OpenSim.Framework.Monitoring | |||
54 | public static SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>> RegisteredStats | 59 | public static SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>> RegisteredStats |
55 | = new SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>>(); | 60 | = new SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>>(); |
56 | 61 | ||
57 | private static AssetStatsCollector assetStats; | 62 | // private static AssetStatsCollector assetStats; |
58 | private static UserStatsCollector userStats; | 63 | // private static UserStatsCollector userStats; |
59 | private static SimExtraStatsCollector simExtraStats = new SimExtraStatsCollector(); | 64 | // private static SimExtraStatsCollector simExtraStats = new SimExtraStatsCollector(); |
60 | 65 | ||
61 | public static AssetStatsCollector AssetStats { get { return assetStats; } } | 66 | // public static AssetStatsCollector AssetStats { get { return assetStats; } } |
62 | public static UserStatsCollector UserStats { get { return userStats; } } | 67 | // public static UserStatsCollector UserStats { get { return userStats; } } |
63 | public static SimExtraStatsCollector SimExtraStats { get { return simExtraStats; } } | 68 | public static SimExtraStatsCollector SimExtraStats { get; set; } |
64 | 69 | ||
65 | public static void RegisterConsoleCommands(ICommandConsole console) | 70 | public static void RegisterConsoleCommands(ICommandConsole console) |
66 | { | 71 | { |
@@ -68,14 +73,18 @@ namespace OpenSim.Framework.Monitoring | |||
68 | "General", | 73 | "General", |
69 | false, | 74 | false, |
70 | "show stats", | 75 | "show stats", |
71 | "show stats [list|all|<category>]", | 76 | "show stats [list|all|(<category>[.<container>])+", |
72 | "Show statistical information for this server", | 77 | "Show statistical information for this server", |
73 | "If no final argument is specified then legacy statistics information is currently shown.\n" | 78 | "If no final argument is specified then legacy statistics information is currently shown.\n" |
74 | + "If list is specified then statistic categories are shown.\n" | 79 | + "'list' argument will show statistic categories.\n" |
75 | + "If all is specified then all registered statistics are shown.\n" | 80 | + "'all' will show all statistics.\n" |
76 | + "If a category name is specified then only statistics from that category are shown.\n" | 81 | + "A <category> name will show statistics from that category.\n" |
82 | + "A <category>.<container> name will show statistics from that category in that container.\n" | ||
83 | + "More than one name can be given separated by spaces.\n" | ||
77 | + "THIS STATS FACILITY IS EXPERIMENTAL AND DOES NOT YET CONTAIN ALL STATS", | 84 | + "THIS STATS FACILITY IS EXPERIMENTAL AND DOES NOT YET CONTAIN ALL STATS", |
78 | HandleShowStatsCommand); | 85 | HandleShowStatsCommand); |
86 | |||
87 | StatsLogger.RegisterConsoleCommands(console); | ||
79 | } | 88 | } |
80 | 89 | ||
81 | public static void HandleShowStatsCommand(string module, string[] cmd) | 90 | public static void HandleShowStatsCommand(string module, string[] cmd) |
@@ -84,43 +93,47 @@ namespace OpenSim.Framework.Monitoring | |||
84 | 93 | ||
85 | if (cmd.Length > 2) | 94 | if (cmd.Length > 2) |
86 | { | 95 | { |
87 | var categoryName = cmd[2]; | 96 | foreach (string name in cmd.Skip(2)) |
88 | var containerName = cmd.Length > 3 ? cmd[3] : String.Empty; | ||
89 | |||
90 | if (categoryName == AllSubCommand) | ||
91 | { | 97 | { |
92 | foreach (var category in RegisteredStats.Values) | 98 | string[] components = name.Split('.'); |
99 | |||
100 | string categoryName = components[0]; | ||
101 | string containerName = components.Length > 1 ? components[1] : null; | ||
102 | |||
103 | if (categoryName == AllSubCommand) | ||
93 | { | 104 | { |
94 | OutputCategoryStatsToConsole(con, category); | 105 | OutputAllStatsToConsole(con); |
95 | } | 106 | } |
96 | } | 107 | else if (categoryName == ListSubCommand) |
97 | else if (categoryName == ListSubCommand) | ||
98 | { | ||
99 | con.Output("Statistic categories available are:"); | ||
100 | foreach (string category in RegisteredStats.Keys) | ||
101 | con.OutputFormat(" {0}", category); | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | SortedDictionary<string, SortedDictionary<string, Stat>> category; | ||
106 | if (!RegisteredStats.TryGetValue(categoryName, out category)) | ||
107 | { | 108 | { |
108 | con.OutputFormat("No such category as {0}", categoryName); | 109 | con.Output("Statistic categories available are:"); |
110 | foreach (string category in RegisteredStats.Keys) | ||
111 | con.OutputFormat(" {0}", category); | ||
109 | } | 112 | } |
110 | else | 113 | else |
111 | { | 114 | { |
112 | if (String.IsNullOrEmpty(containerName)) | 115 | SortedDictionary<string, SortedDictionary<string, Stat>> category; |
113 | OutputCategoryStatsToConsole(con, category); | 116 | if (!RegisteredStats.TryGetValue(categoryName, out category)) |
117 | { | ||
118 | con.OutputFormat("No such category as {0}", categoryName); | ||
119 | } | ||
114 | else | 120 | else |
115 | { | 121 | { |
116 | SortedDictionary<string, Stat> container; | 122 | if (String.IsNullOrEmpty(containerName)) |
117 | if (category.TryGetValue(containerName, out container)) | ||
118 | { | 123 | { |
119 | OutputContainerStatsToConsole(con, container); | 124 | OutputCategoryStatsToConsole(con, category); |
120 | } | 125 | } |
121 | else | 126 | else |
122 | { | 127 | { |
123 | con.OutputFormat("No such container {0} in category {1}", containerName, categoryName); | 128 | SortedDictionary<string, Stat> container; |
129 | if (category.TryGetValue(containerName, out container)) | ||
130 | { | ||
131 | OutputContainerStatsToConsole(con, container); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | con.OutputFormat("No such container {0} in category {1}", containerName, categoryName); | ||
136 | } | ||
124 | } | 137 | } |
125 | } | 138 | } |
126 | } | 139 | } |
@@ -129,51 +142,187 @@ namespace OpenSim.Framework.Monitoring | |||
129 | else | 142 | else |
130 | { | 143 | { |
131 | // Legacy | 144 | // Legacy |
132 | con.Output(SimExtraStats.Report()); | 145 | if (SimExtraStats != null) |
146 | con.Output(SimExtraStats.Report()); | ||
147 | else | ||
148 | OutputAllStatsToConsole(con); | ||
133 | } | 149 | } |
134 | } | 150 | } |
135 | 151 | ||
152 | public static List<string> GetAllStatsReports() | ||
153 | { | ||
154 | List<string> reports = new List<string>(); | ||
155 | |||
156 | foreach (var category in RegisteredStats.Values) | ||
157 | reports.AddRange(GetCategoryStatsReports(category)); | ||
158 | |||
159 | return reports; | ||
160 | } | ||
161 | |||
162 | private static void OutputAllStatsToConsole(ICommandConsole con) | ||
163 | { | ||
164 | foreach (string report in GetAllStatsReports()) | ||
165 | con.Output(report); | ||
166 | } | ||
167 | |||
168 | private static List<string> GetCategoryStatsReports( | ||
169 | SortedDictionary<string, SortedDictionary<string, Stat>> category) | ||
170 | { | ||
171 | List<string> reports = new List<string>(); | ||
172 | |||
173 | foreach (var container in category.Values) | ||
174 | reports.AddRange(GetContainerStatsReports(container)); | ||
175 | |||
176 | return reports; | ||
177 | } | ||
178 | |||
136 | private static void OutputCategoryStatsToConsole( | 179 | private static void OutputCategoryStatsToConsole( |
137 | ICommandConsole con, SortedDictionary<string, SortedDictionary<string, Stat>> category) | 180 | ICommandConsole con, SortedDictionary<string, SortedDictionary<string, Stat>> category) |
138 | { | 181 | { |
139 | foreach (var container in category.Values) | 182 | foreach (string report in GetCategoryStatsReports(category)) |
140 | { | 183 | con.Output(report); |
141 | OutputContainerStatsToConsole(con, container); | ||
142 | } | ||
143 | } | 184 | } |
144 | 185 | ||
145 | private static void OutputContainerStatsToConsole( ICommandConsole con, SortedDictionary<string, Stat> container) | 186 | private static List<string> GetContainerStatsReports(SortedDictionary<string, Stat> container) |
146 | { | 187 | { |
188 | List<string> reports = new List<string>(); | ||
189 | |||
147 | foreach (Stat stat in container.Values) | 190 | foreach (Stat stat in container.Values) |
148 | { | 191 | reports.Add(stat.ToConsoleString()); |
149 | con.Output(stat.ToConsoleString()); | 192 | |
150 | } | 193 | return reports; |
151 | } | 194 | } |
152 | 195 | ||
153 | /// <summary> | 196 | private static void OutputContainerStatsToConsole( |
154 | /// Start collecting statistics related to assets. | 197 | ICommandConsole con, SortedDictionary<string, Stat> container) |
155 | /// Should only be called once. | 198 | { |
156 | /// </summary> | 199 | foreach (string report in GetContainerStatsReports(container)) |
157 | public static AssetStatsCollector StartCollectingAssetStats() | 200 | con.Output(report); |
201 | } | ||
202 | |||
203 | // Creates an OSDMap of the format: | ||
204 | // { categoryName: { | ||
205 | // containerName: { | ||
206 | // statName: { | ||
207 | // "Name": name, | ||
208 | // "ShortName": shortName, | ||
209 | // ... | ||
210 | // }, | ||
211 | // statName: { | ||
212 | // "Name": name, | ||
213 | // "ShortName": shortName, | ||
214 | // ... | ||
215 | // }, | ||
216 | // ... | ||
217 | // }, | ||
218 | // containerName: { | ||
219 | // ... | ||
220 | // }, | ||
221 | // ... | ||
222 | // }, | ||
223 | // categoryName: { | ||
224 | // ... | ||
225 | // }, | ||
226 | // ... | ||
227 | // } | ||
228 | // The passed in parameters will filter the categories, containers and stats returned. If any of the | ||
229 | // parameters are either EmptyOrNull or the AllSubCommand value, all of that type will be returned. | ||
230 | // Case matters. | ||
231 | public static OSDMap GetStatsAsOSDMap(string pCategoryName, string pContainerName, string pStatName) | ||
158 | { | 232 | { |
159 | assetStats = new AssetStatsCollector(); | 233 | OSDMap map = new OSDMap(); |
234 | |||
235 | foreach (string catName in RegisteredStats.Keys) | ||
236 | { | ||
237 | // Do this category if null spec, "all" subcommand or category name matches passed parameter. | ||
238 | // Skip category if none of the above. | ||
239 | if (!(String.IsNullOrEmpty(pCategoryName) || pCategoryName == AllSubCommand || pCategoryName == catName)) | ||
240 | continue; | ||
160 | 241 | ||
161 | return assetStats; | 242 | OSDMap contMap = new OSDMap(); |
243 | foreach (string contName in RegisteredStats[catName].Keys) | ||
244 | { | ||
245 | if (!(string.IsNullOrEmpty(pContainerName) || pContainerName == AllSubCommand || pContainerName == contName)) | ||
246 | continue; | ||
247 | |||
248 | OSDMap statMap = new OSDMap(); | ||
249 | |||
250 | SortedDictionary<string, Stat> theStats = RegisteredStats[catName][contName]; | ||
251 | foreach (string statName in theStats.Keys) | ||
252 | { | ||
253 | if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName)) | ||
254 | continue; | ||
255 | |||
256 | statMap.Add(statName, theStats[statName].ToOSDMap()); | ||
257 | } | ||
258 | |||
259 | contMap.Add(contName, statMap); | ||
260 | } | ||
261 | map.Add(catName, contMap); | ||
262 | } | ||
263 | |||
264 | return map; | ||
162 | } | 265 | } |
163 | 266 | ||
164 | /// <summary> | 267 | public static Hashtable HandleStatsRequest(Hashtable request) |
165 | /// Start collecting statistics related to users. | ||
166 | /// Should only be called once. | ||
167 | /// </summary> | ||
168 | public static UserStatsCollector StartCollectingUserStats() | ||
169 | { | 268 | { |
170 | userStats = new UserStatsCollector(); | 269 | Hashtable responsedata = new Hashtable(); |
270 | // string regpath = request["uri"].ToString(); | ||
271 | int response_code = 200; | ||
272 | string contenttype = "text/json"; | ||
273 | |||
274 | string pCategoryName = StatsManager.AllSubCommand; | ||
275 | string pContainerName = StatsManager.AllSubCommand; | ||
276 | string pStatName = StatsManager.AllSubCommand; | ||
277 | |||
278 | if (request.ContainsKey("cat")) pCategoryName = request["cat"].ToString(); | ||
279 | if (request.ContainsKey("cont")) pContainerName = request["cat"].ToString(); | ||
280 | if (request.ContainsKey("stat")) pStatName = request["cat"].ToString(); | ||
281 | |||
282 | string strOut = StatsManager.GetStatsAsOSDMap(pCategoryName, pContainerName, pStatName).ToString(); | ||
283 | |||
284 | // If requestor wants it as a callback function, build response as a function rather than just the JSON string. | ||
285 | if (request.ContainsKey("callback")) | ||
286 | { | ||
287 | strOut = request["callback"].ToString() + "(" + strOut + ");"; | ||
288 | } | ||
171 | 289 | ||
172 | return userStats; | 290 | // m_log.DebugFormat("{0} StatFetch: uri={1}, cat={2}, cont={3}, stat={4}, resp={5}", |
291 | // LogHeader, regpath, pCategoryName, pContainerName, pStatName, strOut); | ||
292 | |||
293 | responsedata["int_response_code"] = response_code; | ||
294 | responsedata["content_type"] = contenttype; | ||
295 | responsedata["keepalive"] = false; | ||
296 | responsedata["str_response_string"] = strOut; | ||
297 | responsedata["access_control_allow_origin"] = "*"; | ||
298 | |||
299 | return responsedata; | ||
173 | } | 300 | } |
174 | 301 | ||
302 | // /// <summary> | ||
303 | // /// Start collecting statistics related to assets. | ||
304 | // /// Should only be called once. | ||
305 | // /// </summary> | ||
306 | // public static AssetStatsCollector StartCollectingAssetStats() | ||
307 | // { | ||
308 | // assetStats = new AssetStatsCollector(); | ||
309 | // | ||
310 | // return assetStats; | ||
311 | // } | ||
312 | // | ||
313 | // /// <summary> | ||
314 | // /// Start collecting statistics related to users. | ||
315 | // /// Should only be called once. | ||
316 | // /// </summary> | ||
317 | // public static UserStatsCollector StartCollectingUserStats() | ||
318 | // { | ||
319 | // userStats = new UserStatsCollector(); | ||
320 | // | ||
321 | // return userStats; | ||
322 | // } | ||
323 | |||
175 | /// <summary> | 324 | /// <summary> |
176 | /// Registers a statistic. | 325 | /// Register a statistic. |
177 | /// </summary> | 326 | /// </summary> |
178 | /// <param name='stat'></param> | 327 | /// <param name='stat'></param> |
179 | /// <returns></returns> | 328 | /// <returns></returns> |
@@ -187,7 +336,7 @@ namespace OpenSim.Framework.Monitoring | |||
187 | // Stat name is not unique across category/container/shortname key. | 336 | // Stat name is not unique across category/container/shortname key. |
188 | // XXX: For now just return false. This is to avoid problems in regression tests where all tests | 337 | // XXX: For now just return false. This is to avoid problems in regression tests where all tests |
189 | // in a class are run in the same instance of the VM. | 338 | // in a class are run in the same instance of the VM. |
190 | if (TryGetStat(stat, out category, out container)) | 339 | if (TryGetStatParents(stat, out category, out container)) |
191 | return false; | 340 | return false; |
192 | 341 | ||
193 | // We take a copy-on-write approach here of replacing dictionaries when keys are added or removed. | 342 | // We take a copy-on-write approach here of replacing dictionaries when keys are added or removed. |
@@ -223,7 +372,7 @@ namespace OpenSim.Framework.Monitoring | |||
223 | 372 | ||
224 | lock (RegisteredStats) | 373 | lock (RegisteredStats) |
225 | { | 374 | { |
226 | if (!TryGetStat(stat, out category, out container)) | 375 | if (!TryGetStatParents(stat, out category, out container)) |
227 | return false; | 376 | return false; |
228 | 377 | ||
229 | newContainer = new SortedDictionary<string, Stat>(container); | 378 | newContainer = new SortedDictionary<string, Stat>(container); |
@@ -239,12 +388,67 @@ namespace OpenSim.Framework.Monitoring | |||
239 | } | 388 | } |
240 | } | 389 | } |
241 | 390 | ||
242 | public static bool TryGetStats(string category, out SortedDictionary<string, SortedDictionary<string, Stat>> stats) | 391 | public static bool TryGetStat(string category, string container, string statShortName, out Stat stat) |
243 | { | 392 | { |
244 | return RegisteredStats.TryGetValue(category, out stats); | 393 | stat = null; |
394 | SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats; | ||
395 | |||
396 | lock (RegisteredStats) | ||
397 | { | ||
398 | if (!TryGetStatsForCategory(category, out categoryStats)) | ||
399 | return false; | ||
400 | |||
401 | SortedDictionary<string, Stat> containerStats; | ||
402 | |||
403 | if (!categoryStats.TryGetValue(container, out containerStats)) | ||
404 | return false; | ||
405 | |||
406 | return containerStats.TryGetValue(statShortName, out stat); | ||
407 | } | ||
408 | } | ||
409 | |||
410 | public static bool TryGetStatsForCategory( | ||
411 | string category, out SortedDictionary<string, SortedDictionary<string, Stat>> stats) | ||
412 | { | ||
413 | lock (RegisteredStats) | ||
414 | return RegisteredStats.TryGetValue(category, out stats); | ||
415 | } | ||
416 | |||
417 | /// <summary> | ||
418 | /// Get the same stat for each container in a given category. | ||
419 | /// </summary> | ||
420 | /// <returns> | ||
421 | /// The stats if there were any to fetch. Otherwise null. | ||
422 | /// </returns> | ||
423 | /// <param name='category'></param> | ||
424 | /// <param name='statShortName'></param> | ||
425 | public static List<Stat> GetStatsFromEachContainer(string category, string statShortName) | ||
426 | { | ||
427 | SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats; | ||
428 | |||
429 | lock (RegisteredStats) | ||
430 | { | ||
431 | if (!RegisteredStats.TryGetValue(category, out categoryStats)) | ||
432 | return null; | ||
433 | |||
434 | List<Stat> stats = null; | ||
435 | |||
436 | foreach (SortedDictionary<string, Stat> containerStats in categoryStats.Values) | ||
437 | { | ||
438 | if (containerStats.ContainsKey(statShortName)) | ||
439 | { | ||
440 | if (stats == null) | ||
441 | stats = new List<Stat>(); | ||
442 | |||
443 | stats.Add(containerStats[statShortName]); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | return stats; | ||
448 | } | ||
245 | } | 449 | } |
246 | 450 | ||
247 | public static bool TryGetStat( | 451 | public static bool TryGetStatParents( |
248 | Stat stat, | 452 | Stat stat, |
249 | out SortedDictionary<string, SortedDictionary<string, Stat>> category, | 453 | out SortedDictionary<string, SortedDictionary<string, Stat>> category, |
250 | out SortedDictionary<string, Stat> container) | 454 | out SortedDictionary<string, Stat> container) |
diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs index 69d2db5..32724ec 100644 --- a/OpenSim/Framework/Monitoring/Watchdog.cs +++ b/OpenSim/Framework/Monitoring/Watchdog.cs | |||
@@ -380,6 +380,7 @@ namespace OpenSim.Framework.Monitoring | |||
380 | if (MemoryWatchdog.Enabled) | 380 | if (MemoryWatchdog.Enabled) |
381 | MemoryWatchdog.Update(); | 381 | MemoryWatchdog.Update(); |
382 | 382 | ||
383 | ChecksManager.CheckChecks(); | ||
383 | StatsManager.RecordStats(); | 384 | StatsManager.RecordStats(); |
384 | 385 | ||
385 | m_watchdogTimer.Start(); | 386 | m_watchdogTimer.Start(); |