1
0

SimStatsAJAX.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using Mono.Data.SqliteClient;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Framework.Monitoring;
  37. namespace OpenSim.Region.UserStatistics
  38. {
  39. public class SimStatsAJAX : IStatsController
  40. {
  41. #region IStatsController Members
  42. public string ReportName
  43. {
  44. get { return ""; }
  45. }
  46. public Hashtable ProcessModel(Hashtable pParams)
  47. {
  48. List<Scene> m_scene = (List<Scene>)pParams["Scenes"];
  49. Hashtable nh = new Hashtable();
  50. nh.Add("hdata", m_scene);
  51. nh.Add("simstats", pParams["SimStats"]);
  52. return nh;
  53. }
  54. public string RenderView(Hashtable pModelResult)
  55. {
  56. StringBuilder output = new StringBuilder();
  57. List<Scene> all_scenes = (List<Scene>) pModelResult["hdata"];
  58. Dictionary<UUID, USimStatsData> sdatadic = (Dictionary<UUID,USimStatsData>)pModelResult["simstats"];
  59. const string TableClass = "defaultr";
  60. const string TRClass = "defaultr";
  61. const string TDHeaderClass = "header";
  62. const string TDDataClass = "content";
  63. //const string TDDataClassRight = "contentright";
  64. const string TDDataClassCenter = "contentcenter";
  65. foreach (USimStatsData sdata in sdatadic.Values)
  66. {
  67. foreach (Scene sn in all_scenes)
  68. {
  69. if (sn.RegionInfo.RegionID == sdata.RegionId)
  70. {
  71. output.Append("<H2>");
  72. output.Append(sn.RegionInfo.RegionName);
  73. output.Append("</H2>");
  74. }
  75. }
  76. HTMLUtil.TABLE_O(ref output, TableClass);
  77. HTMLUtil.TR_O(ref output, TRClass);
  78. HTMLUtil.TD_O(ref output, TDHeaderClass);
  79. output.Append("Dilatn");
  80. HTMLUtil.TD_C(ref output);
  81. HTMLUtil.TD_O(ref output, TDHeaderClass);
  82. output.Append("SimFPS");
  83. HTMLUtil.TD_C(ref output);
  84. HTMLUtil.TD_O(ref output, TDHeaderClass);
  85. output.Append("PhysFPS");
  86. HTMLUtil.TD_C(ref output);
  87. HTMLUtil.TD_O(ref output, TDHeaderClass);
  88. output.Append("AgntUp");
  89. HTMLUtil.TD_C(ref output);
  90. HTMLUtil.TD_O(ref output, TDHeaderClass);
  91. output.Append("RootAg");
  92. HTMLUtil.TD_C(ref output);
  93. HTMLUtil.TD_O(ref output, TDHeaderClass);
  94. output.Append("ChldAg");
  95. HTMLUtil.TD_C(ref output);
  96. HTMLUtil.TD_O(ref output, TDHeaderClass);
  97. output.Append("Prims");
  98. HTMLUtil.TD_C(ref output);
  99. HTMLUtil.TD_O(ref output, TDHeaderClass);
  100. output.Append("ATvPrm");
  101. HTMLUtil.TD_C(ref output);
  102. HTMLUtil.TD_O(ref output, TDHeaderClass);
  103. output.Append("AtvScr");
  104. HTMLUtil.TD_C(ref output);
  105. HTMLUtil.TD_O(ref output, TDHeaderClass);
  106. output.Append("ScrLPS");
  107. HTMLUtil.TD_C(ref output);
  108. HTMLUtil.TR_C(ref output);
  109. HTMLUtil.TR_O(ref output, TRClass);
  110. HTMLUtil.TD_O(ref output, TDDataClass);
  111. output.Append(sdata.TimeDilation);
  112. HTMLUtil.TD_C(ref output);
  113. HTMLUtil.TD_O(ref output, TDDataClass);
  114. output.Append(sdata.SimFps);
  115. HTMLUtil.TD_C(ref output);
  116. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  117. output.Append(sdata.PhysicsFps);
  118. HTMLUtil.TD_C(ref output);
  119. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  120. output.Append(sdata.AgentUpdates);
  121. HTMLUtil.TD_C(ref output);
  122. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  123. output.Append(sdata.RootAgents);
  124. HTMLUtil.TD_C(ref output);
  125. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  126. output.Append(sdata.ChildAgents);
  127. HTMLUtil.TD_C(ref output);
  128. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  129. output.Append(sdata.TotalPrims);
  130. HTMLUtil.TD_C(ref output);
  131. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  132. output.Append(sdata.ActivePrims);
  133. HTMLUtil.TD_C(ref output);
  134. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  135. output.Append(sdata.ActiveScripts);
  136. HTMLUtil.TD_C(ref output);
  137. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  138. output.Append(sdata.ScriptLinesPerSecond);
  139. HTMLUtil.TD_C(ref output);
  140. HTMLUtil.TR_C(ref output);
  141. HTMLUtil.TR_O(ref output, TRClass);
  142. HTMLUtil.TD_O(ref output, TDHeaderClass);
  143. output.Append("FrmMS");
  144. HTMLUtil.TD_C(ref output);
  145. HTMLUtil.TD_O(ref output, TDHeaderClass);
  146. output.Append("AgtMS");
  147. HTMLUtil.TD_C(ref output);
  148. HTMLUtil.TD_O(ref output, TDHeaderClass);
  149. output.Append("PhysMS");
  150. HTMLUtil.TD_C(ref output);
  151. HTMLUtil.TD_O(ref output, TDHeaderClass);
  152. output.Append("OthrMS");
  153. HTMLUtil.TD_C(ref output);
  154. HTMLUtil.TD_O(ref output, TDHeaderClass);
  155. output.Append("ScrLPS");
  156. HTMLUtil.TD_C(ref output);
  157. HTMLUtil.TD_O(ref output, TDHeaderClass);
  158. output.Append("OutPPS");
  159. HTMLUtil.TD_C(ref output);
  160. HTMLUtil.TD_O(ref output, TDHeaderClass);
  161. output.Append("InPPS");
  162. HTMLUtil.TD_C(ref output);
  163. HTMLUtil.TD_O(ref output, TDHeaderClass);
  164. output.Append("NoAckKB");
  165. HTMLUtil.TD_C(ref output);
  166. HTMLUtil.TD_O(ref output, TDHeaderClass);
  167. output.Append("PndDWN");
  168. HTMLUtil.TD_C(ref output);
  169. HTMLUtil.TD_O(ref output, TDHeaderClass);
  170. output.Append("PndUP");
  171. HTMLUtil.TD_C(ref output);
  172. HTMLUtil.TR_C(ref output);
  173. HTMLUtil.TR_O(ref output, TRClass);
  174. HTMLUtil.TD_O(ref output, TDDataClass);
  175. output.Append(sdata.TotalFrameTime);
  176. HTMLUtil.TD_C(ref output);
  177. HTMLUtil.TD_O(ref output, TDDataClass);
  178. output.Append(sdata.AgentFrameTime);
  179. HTMLUtil.TD_C(ref output);
  180. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  181. output.Append(sdata.PhysicsFrameTime);
  182. HTMLUtil.TD_C(ref output);
  183. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  184. output.Append(sdata.OtherFrameTime);
  185. HTMLUtil.TD_C(ref output);
  186. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  187. output.Append(sdata.ScriptLinesPerSecond);
  188. HTMLUtil.TD_C(ref output);
  189. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  190. output.Append(sdata.OutPacketsPerSecond);
  191. HTMLUtil.TD_C(ref output);
  192. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  193. output.Append(sdata.InPacketsPerSecond);
  194. HTMLUtil.TD_C(ref output);
  195. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  196. output.Append(sdata.UnackedBytes);
  197. HTMLUtil.TD_C(ref output);
  198. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  199. output.Append(sdata.PendingDownloads);
  200. HTMLUtil.TD_C(ref output);
  201. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  202. output.Append(sdata.PendingUploads);
  203. HTMLUtil.TD_C(ref output);
  204. HTMLUtil.TR_C(ref output);
  205. HTMLUtil.TABLE_C(ref output);
  206. }
  207. return output.ToString();
  208. }
  209. /// <summary>
  210. /// Return stat information for all regions in the sim. Returns data of the form:
  211. /// <pre>
  212. /// {"REGIONNAME": {
  213. /// "region": "REGIONNAME",
  214. /// "timeDilation": "101",
  215. /// ... // the rest of the stat info
  216. /// },
  217. /// ... // entries for each region
  218. /// }
  219. /// </pre>
  220. /// </summary>
  221. /// <param name="pModelResult"></param>
  222. /// <returns></returns>
  223. public string RenderJson(Hashtable pModelResult)
  224. {
  225. List<Scene> all_scenes = (List<Scene>) pModelResult["hdata"];
  226. Dictionary<UUID, USimStatsData> sdatadic = (Dictionary<UUID,USimStatsData>)pModelResult["simstats"];
  227. OSDMap allStatsInfo = new OpenMetaverse.StructuredData.OSDMap();
  228. foreach (USimStatsData sdata in sdatadic.Values)
  229. {
  230. OSDMap statsInfo = new OpenMetaverse.StructuredData.OSDMap();
  231. string regionName = "unknown";
  232. foreach (Scene sn in all_scenes)
  233. {
  234. if (sn.RegionInfo.RegionID == sdata.RegionId)
  235. {
  236. regionName = sn.RegionInfo.RegionName;
  237. break;
  238. }
  239. }
  240. statsInfo.Add("region", new OSDString(regionName));
  241. statsInfo.Add("timeDilation", new OSDString(sdata.TimeDilation.ToString()));
  242. statsInfo.Add("simFPS", new OSDString(sdata.SimFps.ToString()));
  243. statsInfo.Add("physicsFPS", new OSDString(sdata.PhysicsFps.ToString()));
  244. statsInfo.Add("agentUpdates", new OSDString(sdata.AgentUpdates.ToString()));
  245. statsInfo.Add("rootAgents", new OSDString(sdata.RootAgents.ToString()));
  246. statsInfo.Add("childAgents", new OSDString(sdata.ChildAgents.ToString()));
  247. statsInfo.Add("totalPrims", new OSDString(sdata.TotalPrims.ToString()));
  248. statsInfo.Add("activePrims", new OSDString(sdata.ActivePrims.ToString()));
  249. statsInfo.Add("activeScripts", new OSDString(sdata.ActiveScripts.ToString()));
  250. statsInfo.Add("scriptLinesPerSec", new OSDString(sdata.ScriptLinesPerSecond.ToString()));
  251. statsInfo.Add("totalFrameTime", new OSDString(sdata.TotalFrameTime.ToString()));
  252. statsInfo.Add("agentFrameTime", new OSDString(sdata.AgentFrameTime.ToString()));
  253. statsInfo.Add("physicsFrameTime", new OSDString(sdata.PhysicsFrameTime.ToString()));
  254. statsInfo.Add("otherFrameTime", new OSDString(sdata.OtherFrameTime.ToString()));
  255. statsInfo.Add("outPacketsPerSec", new OSDString(sdata.OutPacketsPerSecond.ToString()));
  256. statsInfo.Add("inPacketsPerSec", new OSDString(sdata.InPacketsPerSecond.ToString()));
  257. statsInfo.Add("unackedByptes", new OSDString(sdata.UnackedBytes.ToString()));
  258. statsInfo.Add("pendingDownloads", new OSDString(sdata.PendingDownloads.ToString()));
  259. statsInfo.Add("pendingUploads", new OSDString(sdata.PendingUploads.ToString()));
  260. allStatsInfo.Add(regionName, statsInfo);
  261. }
  262. return allStatsInfo.ToString();
  263. }
  264. #endregion
  265. }
  266. }