LindenUDPInfoModule.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using log4net;
  32. using Mono.Addins;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Statistics;
  38. using OpenSim.Region.ClientStack.LindenUDP;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.CoreModules.UDP.Linden
  42. {
  43. /// <summary>
  44. /// A module that just holds commands for inspecting the current state of the Linden UDP stack.
  45. /// </summary>
  46. /// <remarks>
  47. /// All actual client stack functionality remains in OpenSim.Region.ClientStack.LindenUDP
  48. /// </remarks>
  49. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LindenUDPInfoModule")]
  50. public class LindenUDPInfoModule : ISharedRegionModule
  51. {
  52. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. protected Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
  54. public string Name { get { return "Linden UDP Module"; } }
  55. public Type ReplaceableInterface { get { return null; } }
  56. public void Initialise(IConfigSource source)
  57. {
  58. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: INITIALIZED MODULE");
  59. }
  60. public void PostInitialise()
  61. {
  62. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: POST INITIALIZED MODULE");
  63. }
  64. public void Close()
  65. {
  66. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: CLOSED MODULE");
  67. }
  68. public void AddRegion(Scene scene)
  69. {
  70. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  71. lock (m_scenes)
  72. m_scenes[scene.RegionInfo.RegionID] = scene;
  73. scene.AddCommand(
  74. this, "show pqueues",
  75. "show pqueues [full]",
  76. "Show priority queue data for each client",
  77. "Without the 'full' option, only root agents are shown."
  78. + " With the 'full' option child agents are also shown.",
  79. ShowPQueuesReport);
  80. scene.AddCommand(
  81. this, "show queues",
  82. "show queues [full]",
  83. "Show queue data for each client",
  84. "Without the 'full' option, only root agents are shown."
  85. + " With the 'full' option child agents are also shown.",
  86. ShowQueuesReport);
  87. scene.AddCommand(
  88. this, "show throttles",
  89. "show throttles [full]",
  90. "Show throttle settings for each client and for the server overall",
  91. "Without the 'full' option, only root agents are shown."
  92. + " With the 'full' option child agents are also shown.",
  93. ShowThrottlesReport);
  94. scene.AddCommand(
  95. this, "emergency-monitoring",
  96. "emergency-monitoring",
  97. "Go on/off emergency monitoring mode",
  98. "Go on/off emergency monitoring mode",
  99. EmergencyMonitoring);
  100. }
  101. public void RemoveRegion(Scene scene)
  102. {
  103. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  104. lock (m_scenes)
  105. m_scenes.Remove(scene.RegionInfo.RegionID);
  106. }
  107. public void RegionLoaded(Scene scene)
  108. {
  109. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  110. }
  111. protected void ShowPQueuesReport(string module, string[] cmd)
  112. {
  113. MainConsole.Instance.Output(GetPQueuesReport(cmd));
  114. }
  115. protected void ShowQueuesReport(string module, string[] cmd)
  116. {
  117. MainConsole.Instance.Output(GetQueuesReport(cmd));
  118. }
  119. protected void ShowThrottlesReport(string module, string[] cmd)
  120. {
  121. MainConsole.Instance.Output(GetThrottlesReport(cmd));
  122. }
  123. protected void EmergencyMonitoring(string module, string[] cmd)
  124. {
  125. bool mode = true;
  126. if (cmd.Length == 1 || (cmd.Length > 1 && cmd[1] == "on"))
  127. {
  128. mode = true;
  129. MainConsole.Instance.Output("Emergency Monitoring ON");
  130. }
  131. else
  132. {
  133. mode = false;
  134. MainConsole.Instance.Output("Emergency Monitoring OFF");
  135. }
  136. foreach (Scene s in m_scenes.Values)
  137. s.EmergencyMonitoring = mode;
  138. }
  139. protected string GetColumnEntry(string entry, int maxLength, int columnPadding)
  140. {
  141. return string.Format(
  142. "{0,-" + maxLength + "}{1,-" + columnPadding + "}",
  143. entry.Length > maxLength ? entry.Substring(0, maxLength) : entry,
  144. "");
  145. }
  146. /// <summary>
  147. /// Generate UDP Queue data report for each client
  148. /// </summary>
  149. /// <param name="showParams"></param>
  150. /// <returns></returns>
  151. protected string GetPQueuesReport(string[] showParams)
  152. {
  153. bool showChildren = false;
  154. string pname = "";
  155. if (showParams.Length > 2 && showParams[2] == "full")
  156. showChildren = true;
  157. else if (showParams.Length > 3)
  158. pname = showParams[2] + " " + showParams[3];
  159. StringBuilder report = new StringBuilder();
  160. int columnPadding = 2;
  161. int maxNameLength = 18;
  162. int maxRegionNameLength = 14;
  163. int maxTypeLength = 4;
  164. // int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  165. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  166. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  167. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  168. report.AppendFormat(
  169. "{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7} {10,7} {11,7}\n",
  170. "Pri 0",
  171. "Pri 1",
  172. "Pri 2",
  173. "Pri 3",
  174. "Pri 4",
  175. "Pri 5",
  176. "Pri 6",
  177. "Pri 7",
  178. "Pri 8",
  179. "Pri 9",
  180. "Pri 10",
  181. "Pri 11");
  182. lock (m_scenes)
  183. {
  184. foreach (Scene scene in m_scenes.Values)
  185. {
  186. scene.ForEachClient(
  187. delegate(IClientAPI client)
  188. {
  189. if (client is LLClientView)
  190. {
  191. bool isChild = scene.PresenceChildStatus(client.AgentId);
  192. if (isChild && !showChildren)
  193. return;
  194. string name = client.Name;
  195. if (pname != "" && name != pname)
  196. return;
  197. string regionName = scene.RegionInfo.RegionName;
  198. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  199. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  200. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  201. report.AppendLine(((LLClientView)client).EntityUpdateQueue.ToString());
  202. }
  203. });
  204. }
  205. }
  206. return report.ToString();
  207. }
  208. /// <summary>
  209. /// Generate UDP Queue data report for each client
  210. /// </summary>
  211. /// <param name="showParams"></param>
  212. /// <returns></returns>
  213. protected string GetQueuesReport(string[] showParams)
  214. {
  215. bool showChildren = false;
  216. string pname = "";
  217. if (showParams.Length > 2 && showParams[2] == "full")
  218. showChildren = true;
  219. else if (showParams.Length > 3)
  220. pname = showParams[2] + " " + showParams[3];
  221. StringBuilder report = new StringBuilder();
  222. int columnPadding = 2;
  223. int maxNameLength = 18;
  224. int maxRegionNameLength = 14;
  225. int maxTypeLength = 4;
  226. int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  227. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  228. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  229. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  230. report.AppendFormat(
  231. "{0,7} {1,7} {2,7} {3,9} {4,7} {5,7} {6,7} {7,7} {8,7} {9,8} {10,7} {11,7}\n",
  232. "Pkts",
  233. "Pkts",
  234. "Pkts",
  235. "Bytes",
  236. "Q Pkts",
  237. "Q Pkts",
  238. "Q Pkts",
  239. "Q Pkts",
  240. "Q Pkts",
  241. "Q Pkts",
  242. "Q Pkts",
  243. "Q Pkts");
  244. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  245. report.AppendFormat(
  246. "{0,7} {1,7} {2,7} {3,9} {4,7} {5,7} {6,7} {7,7} {8,7} {9,8} {10,7} {11,7}\n",
  247. "In",
  248. "Out",
  249. "Resent",
  250. "Unacked",
  251. "Resend",
  252. "Land",
  253. "Wind",
  254. "Cloud",
  255. "Task",
  256. "Texture",
  257. "Asset",
  258. "State");
  259. lock (m_scenes)
  260. {
  261. foreach (Scene scene in m_scenes.Values)
  262. {
  263. scene.ForEachClient(
  264. delegate(IClientAPI client)
  265. {
  266. if (client is IStatsCollector)
  267. {
  268. bool isChild = scene.PresenceChildStatus(client.AgentId);
  269. if (isChild && !showChildren)
  270. return;
  271. string name = client.Name;
  272. if (pname != "" && name != pname)
  273. return;
  274. string regionName = scene.RegionInfo.RegionName;
  275. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  276. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  277. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  278. IStatsCollector stats = (IStatsCollector)client;
  279. report.AppendLine(stats.Report());
  280. }
  281. });
  282. }
  283. }
  284. return report.ToString();
  285. }
  286. /// <summary>
  287. /// Show throttle data
  288. /// </summary>
  289. /// <param name="showParams"></param>
  290. /// <returns></returns>
  291. protected string GetThrottlesReport(string[] showParams)
  292. {
  293. bool showChildren = false;
  294. string pname = "";
  295. if (showParams.Length > 2 && showParams[2] == "full")
  296. showChildren = true;
  297. else if (showParams.Length > 3)
  298. pname = showParams[2] + " " + showParams[3];
  299. StringBuilder report = new StringBuilder();
  300. int columnPadding = 2;
  301. int maxNameLength = 18;
  302. int maxRegionNameLength = 14;
  303. int maxTypeLength = 4;
  304. int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  305. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  306. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  307. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  308. report.AppendFormat(
  309. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}\n",
  310. "Total",
  311. "Resend",
  312. "Land",
  313. "Wind",
  314. "Cloud",
  315. "Task",
  316. "Texture",
  317. "Asset");
  318. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  319. report.AppendFormat(
  320. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  321. "kb/s",
  322. "kb/s",
  323. "kb/s",
  324. "kb/s",
  325. "kb/s",
  326. "kb/s",
  327. "kb/s",
  328. "kb/s");
  329. report.AppendLine();
  330. bool firstClient = true;
  331. lock (m_scenes)
  332. {
  333. foreach (Scene scene in m_scenes.Values)
  334. {
  335. scene.ForEachClient(
  336. delegate(IClientAPI client)
  337. {
  338. if (client is LLClientView)
  339. {
  340. LLClientView llClient = client as LLClientView;
  341. if (firstClient)
  342. {
  343. report.AppendLine(GetServerThrottlesReport(llClient.UDPServer));
  344. firstClient = false;
  345. }
  346. bool isChild = scene.PresenceChildStatus(client.AgentId);
  347. if (isChild && !showChildren)
  348. return;
  349. string name = client.Name;
  350. if (pname != "" && name != pname)
  351. return;
  352. string regionName = scene.RegionInfo.RegionName;
  353. LLUDPClient llUdpClient = llClient.UDPClient;
  354. ClientInfo ci = llUdpClient.GetClientInfo();
  355. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  356. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  357. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  358. report.AppendFormat(
  359. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  360. (ci.totalThrottle * 8) / 1000,
  361. (ci.resendThrottle * 8) / 1000,
  362. (ci.landThrottle * 8) / 1000,
  363. (ci.windThrottle * 8) / 1000,
  364. (ci.cloudThrottle * 8) / 1000,
  365. (ci.taskThrottle * 8) / 1000,
  366. (ci.textureThrottle * 8) / 1000,
  367. (ci.assetThrottle * 8) / 1000);
  368. report.AppendLine();
  369. }
  370. });
  371. }
  372. }
  373. return report.ToString();
  374. }
  375. protected string GetServerThrottlesReport(LLUDPServer udpServer)
  376. {
  377. StringBuilder report = new StringBuilder();
  378. int columnPadding = 2;
  379. int maxNameLength = 18;
  380. int maxRegionNameLength = 14;
  381. int maxTypeLength = 4;
  382. string name = "SERVER AGENT RATES";
  383. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  384. report.Append(GetColumnEntry("-", maxRegionNameLength, columnPadding));
  385. report.Append(GetColumnEntry("-", maxTypeLength, columnPadding));
  386. ThrottleRates throttleRates = udpServer.ThrottleRates;
  387. report.AppendFormat(
  388. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  389. (throttleRates.Total * 8) / 1000,
  390. (throttleRates.Resend * 8) / 1000,
  391. (throttleRates.Land * 8) / 1000,
  392. (throttleRates.Wind * 8) / 1000,
  393. (throttleRates.Cloud * 8) / 1000,
  394. (throttleRates.Task * 8) / 1000,
  395. (throttleRates.Texture * 8) / 1000,
  396. (throttleRates.Asset * 8) / 1000);
  397. return report.ToString();
  398. }
  399. }
  400. }