diff options
author | BlueWall | 2011-01-27 08:53:57 -0500 |
---|---|---|
committer | BlueWall | 2011-01-27 08:53:57 -0500 |
commit | d89d9d1b1310d494fbb7712057eab8a196e10a04 (patch) | |
tree | 62834b7f5954aa8f013a159ee2fc3ccee385e673 /OpenSim/Region/OptionalModules | |
parent | Make FireAndForgetWrapper a singleton class (diff) | |
parent | Make it work (diff) | |
download | opensim-SC-d89d9d1b1310d494fbb7712057eab8a196e10a04.zip opensim-SC-d89d9d1b1310d494fbb7712057eab8a196e10a04.tar.gz opensim-SC-d89d9d1b1310d494fbb7712057eab8a196e10a04.tar.bz2 opensim-SC-d89d9d1b1310d494fbb7712057eab8a196e10a04.tar.xz |
Merge branch 'master' of /home/opensim/src/OpenSim/Core
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r-- | OpenSim/Region/OptionalModules/Agent/UDP/Linden/LindenUDPInfoModule.cs | 348 |
1 files changed, 348 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Agent/UDP/Linden/LindenUDPInfoModule.cs b/OpenSim/Region/OptionalModules/Agent/UDP/Linden/LindenUDPInfoModule.cs new file mode 100644 index 0000000..87d067c --- /dev/null +++ b/OpenSim/Region/OptionalModules/Agent/UDP/Linden/LindenUDPInfoModule.cs | |||
@@ -0,0 +1,348 @@ | |||
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.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using OpenSim.Framework.Statistics; | ||
39 | using OpenSim.Region.ClientStack.LindenUDP; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | |||
43 | namespace OpenSim.Region.CoreModules.UDP.Linden | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// A module that just holds commands for inspecting the current state of the Linden UDP stack. | ||
47 | /// </summary> | ||
48 | /// <remarks> | ||
49 | /// All actual client stack functionality remains in OpenSim.Region.ClientStack.LindenUDP | ||
50 | /// </remarks> | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LindenUDPInfoModule")] | ||
52 | public class LindenUDPInfoModule : ISharedRegionModule | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | protected Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>(); | ||
57 | |||
58 | public string Name { get { return "Linden UDP Module"; } } | ||
59 | |||
60 | public Type ReplaceableInterface { get { return null; } } | ||
61 | |||
62 | public void Initialise(IConfigSource source) | ||
63 | { | ||
64 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: INITIALIZED MODULE"); | ||
65 | } | ||
66 | |||
67 | public void PostInitialise() | ||
68 | { | ||
69 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: POST INITIALIZED MODULE"); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: CLOSED MODULE"); | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene scene) | ||
78 | { | ||
79 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
80 | |||
81 | lock (m_scenes) | ||
82 | m_scenes[scene.RegionInfo.RegionID] = scene; | ||
83 | |||
84 | scene.AddCommand( | ||
85 | this, "show queues", | ||
86 | "show queues [full]", | ||
87 | "Show queue data for each client", | ||
88 | "Without the 'full' option, only root agents are shown." | ||
89 | + " With the 'full' option child agents are also shown.", | ||
90 | ShowQueuesReport); | ||
91 | |||
92 | scene.AddCommand( | ||
93 | this, "show throttles", | ||
94 | "show throttles [full]", | ||
95 | "Show throttle settings for each client and for the server overall", | ||
96 | "Without the 'full' option, only root agents are shown." | ||
97 | + " With the 'full' option child agents are also shown.", | ||
98 | ShowThrottlesReport); | ||
99 | } | ||
100 | |||
101 | public void RemoveRegion(Scene scene) | ||
102 | { | ||
103 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
104 | |||
105 | lock (m_scenes) | ||
106 | m_scenes.Remove(scene.RegionInfo.RegionID); | ||
107 | } | ||
108 | |||
109 | public void RegionLoaded(Scene scene) | ||
110 | { | ||
111 | // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
112 | } | ||
113 | |||
114 | protected void ShowQueuesReport(string module, string[] cmd) | ||
115 | { | ||
116 | MainConsole.Instance.Output(GetQueuesReport(cmd)); | ||
117 | } | ||
118 | |||
119 | protected void ShowThrottlesReport(string module, string[] cmd) | ||
120 | { | ||
121 | MainConsole.Instance.Output(GetThrottlesReport(cmd)); | ||
122 | } | ||
123 | |||
124 | protected string GetColumnEntry(string entry, int maxLength, int columnPadding) | ||
125 | { | ||
126 | return string.Format( | ||
127 | "{0,-" + maxLength + "}{1,-" + columnPadding + "}", | ||
128 | entry.Length > maxLength ? entry.Substring(0, maxLength) : entry, | ||
129 | ""); | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Generate UDP Queue data report for each client | ||
134 | /// </summary> | ||
135 | /// <param name="showParams"></param> | ||
136 | /// <returns></returns> | ||
137 | protected string GetQueuesReport(string[] showParams) | ||
138 | { | ||
139 | bool showChildren = false; | ||
140 | |||
141 | if (showParams.Length > 2 && showParams[2] == "full") | ||
142 | showChildren = true; | ||
143 | |||
144 | StringBuilder report = new StringBuilder(); | ||
145 | |||
146 | int columnPadding = 2; | ||
147 | int maxNameLength = 18; | ||
148 | int maxRegionNameLength = 14; | ||
149 | int maxTypeLength = 4; | ||
150 | int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding; | ||
151 | |||
152 | report.Append(GetColumnEntry("User", maxNameLength, columnPadding)); | ||
153 | report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding)); | ||
154 | report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding)); | ||
155 | |||
156 | report.AppendFormat( | ||
157 | "{0,7} {1,7} {2,9} {3,8} {4,7} {5,7} {6,7} {7,7} {8,9} {9,7} {10,7}\n", | ||
158 | "Pkts", | ||
159 | "Pkts", | ||
160 | "Bytes", | ||
161 | "Pkts", | ||
162 | "Pkts", | ||
163 | "Pkts", | ||
164 | "Pkts", | ||
165 | "Pkts", | ||
166 | "Pkts", | ||
167 | "Pkts", | ||
168 | "Pkts"); | ||
169 | |||
170 | report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", ""); | ||
171 | report.AppendFormat( | ||
172 | "{0,7} {1,7} {2,9} {3,8} {4,7} {5,7} {6,7} {7,7} {8,9} {9,7} {10,7}\n", | ||
173 | "Out", | ||
174 | "In", | ||
175 | "Unacked", | ||
176 | "Resend", | ||
177 | "Land", | ||
178 | "Wind", | ||
179 | "Cloud", | ||
180 | "Task", | ||
181 | "Texture", | ||
182 | "Asset", | ||
183 | "State"); | ||
184 | |||
185 | lock (m_scenes) | ||
186 | { | ||
187 | foreach (Scene scene in m_scenes.Values) | ||
188 | { | ||
189 | scene.ForEachClient( | ||
190 | delegate(IClientAPI client) | ||
191 | { | ||
192 | if (client is IStatsCollector) | ||
193 | { | ||
194 | bool isChild = scene.PresenceChildStatus(client.AgentId); | ||
195 | if (isChild && !showChildren) | ||
196 | return; | ||
197 | |||
198 | string name = client.Name; | ||
199 | string regionName = scene.RegionInfo.RegionName; | ||
200 | |||
201 | report.Append(GetColumnEntry(name, maxNameLength, columnPadding)); | ||
202 | report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding)); | ||
203 | report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding)); | ||
204 | |||
205 | IStatsCollector stats = (IStatsCollector)client; | ||
206 | |||
207 | report.AppendLine(stats.Report()); | ||
208 | } | ||
209 | }); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | return report.ToString(); | ||
214 | } | ||
215 | |||
216 | /// <summary> | ||
217 | /// Show throttle data | ||
218 | /// </summary> | ||
219 | /// <param name="showParams"></param> | ||
220 | /// <returns></returns> | ||
221 | protected string GetThrottlesReport(string[] showParams) | ||
222 | { | ||
223 | bool showChildren = false; | ||
224 | |||
225 | if (showParams.Length > 2 && showParams[2] == "full") | ||
226 | showChildren = true; | ||
227 | |||
228 | StringBuilder report = new StringBuilder(); | ||
229 | |||
230 | int columnPadding = 2; | ||
231 | int maxNameLength = 18; | ||
232 | int maxRegionNameLength = 14; | ||
233 | int maxTypeLength = 4; | ||
234 | int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding; | ||
235 | |||
236 | report.Append(GetColumnEntry("User", maxNameLength, columnPadding)); | ||
237 | report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding)); | ||
238 | report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding)); | ||
239 | |||
240 | report.AppendFormat( | ||
241 | "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}\n", | ||
242 | "Total", | ||
243 | "Resend", | ||
244 | "Land", | ||
245 | "Wind", | ||
246 | "Cloud", | ||
247 | "Task", | ||
248 | "Texture", | ||
249 | "Asset"); | ||
250 | |||
251 | report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", ""); | ||
252 | report.AppendFormat( | ||
253 | "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}", | ||
254 | "kb/s", | ||
255 | "kb/s", | ||
256 | "kb/s", | ||
257 | "kb/s", | ||
258 | "kb/s", | ||
259 | "kb/s", | ||
260 | "kb/s", | ||
261 | "kb/s"); | ||
262 | |||
263 | report.AppendLine(); | ||
264 | |||
265 | bool firstClient = true; | ||
266 | |||
267 | lock (m_scenes) | ||
268 | { | ||
269 | foreach (Scene scene in m_scenes.Values) | ||
270 | { | ||
271 | scene.ForEachClient( | ||
272 | delegate(IClientAPI client) | ||
273 | { | ||
274 | if (client is LLClientView) | ||
275 | { | ||
276 | LLClientView llClient = client as LLClientView; | ||
277 | |||
278 | if (firstClient) | ||
279 | { | ||
280 | report.AppendLine(GetServerThrottlesReport(llClient.UDPServer)); | ||
281 | firstClient = false; | ||
282 | } | ||
283 | |||
284 | bool isChild = scene.PresenceChildStatus(client.AgentId); | ||
285 | if (isChild && !showChildren) | ||
286 | return; | ||
287 | |||
288 | string name = client.Name; | ||
289 | string regionName = scene.RegionInfo.RegionName; | ||
290 | |||
291 | LLUDPClient llUdpClient = llClient.UDPClient; | ||
292 | ClientInfo ci = llUdpClient.GetClientInfo(); | ||
293 | |||
294 | report.Append(GetColumnEntry(name, maxNameLength, columnPadding)); | ||
295 | report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding)); | ||
296 | report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding)); | ||
297 | |||
298 | report.AppendFormat( | ||
299 | "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}", | ||
300 | (ci.totalThrottle * 8) / 1000, | ||
301 | (ci.resendThrottle * 8) / 1000, | ||
302 | (ci.landThrottle * 8) / 1000, | ||
303 | (ci.windThrottle * 8) / 1000, | ||
304 | (ci.cloudThrottle * 8) / 1000, | ||
305 | (ci.taskThrottle * 8) / 1000, | ||
306 | (ci.textureThrottle * 8) / 1000, | ||
307 | (ci.assetThrottle * 8) / 1000); | ||
308 | |||
309 | report.AppendLine(); | ||
310 | } | ||
311 | }); | ||
312 | } | ||
313 | } | ||
314 | |||
315 | return report.ToString(); | ||
316 | } | ||
317 | |||
318 | protected string GetServerThrottlesReport(LLUDPServer udpServer) | ||
319 | { | ||
320 | StringBuilder report = new StringBuilder(); | ||
321 | |||
322 | int columnPadding = 2; | ||
323 | int maxNameLength = 18; | ||
324 | int maxRegionNameLength = 14; | ||
325 | int maxTypeLength = 4; | ||
326 | |||
327 | string name = "SERVER AGENT LIMITS"; | ||
328 | |||
329 | report.Append(GetColumnEntry(name, maxNameLength, columnPadding)); | ||
330 | report.Append(GetColumnEntry("-", maxRegionNameLength, columnPadding)); | ||
331 | report.Append(GetColumnEntry("-", maxTypeLength, columnPadding)); | ||
332 | |||
333 | ThrottleRates throttleRates = udpServer.ThrottleRates; | ||
334 | report.AppendFormat( | ||
335 | "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}", | ||
336 | "n/a", | ||
337 | (throttleRates.ResendLimit * 8) / 1000, | ||
338 | (throttleRates.LandLimit * 8) / 1000, | ||
339 | (throttleRates.WindLimit * 8) / 1000, | ||
340 | (throttleRates.CloudLimit * 8) / 1000, | ||
341 | (throttleRates.TaskLimit * 8) / 1000, | ||
342 | (throttleRates.TextureLimit * 8) / 1000, | ||
343 | (throttleRates.AssetLimit * 8) / 1000); | ||
344 | |||
345 | return report.ToString(); | ||
346 | } | ||
347 | } | ||
348 | } \ No newline at end of file | ||