1
0

Default_Report.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 Default_Report : IStatsController
  40. {
  41. public string ReportName
  42. {
  43. get { return "Home"; }
  44. }
  45. #region IStatsController Members
  46. public Hashtable ProcessModel(Hashtable pParams)
  47. {
  48. SqliteConnection conn = (SqliteConnection)pParams["DatabaseConnection"];
  49. List<Scene> m_scene = (List<Scene>)pParams["Scenes"];
  50. stats_default_page_values mData = rep_DefaultReport_data(conn, m_scene);
  51. mData.sim_stat_data = (Dictionary<UUID,USimStatsData>)pParams["SimStats"];
  52. mData.stats_reports = (Dictionary<string, IStatsController>) pParams["Reports"];
  53. Hashtable nh = new Hashtable();
  54. nh.Add("hdata", mData);
  55. nh.Add("Reports", pParams["Reports"]);
  56. return nh;
  57. }
  58. public string RenderView(Hashtable pModelResult)
  59. {
  60. stats_default_page_values mData = (stats_default_page_values) pModelResult["hdata"];
  61. return rep_Default_report_view(mData);
  62. }
  63. #endregion
  64. public string rep_Default_report_view(stats_default_page_values values)
  65. {
  66. StringBuilder output = new StringBuilder();
  67. const string TableClass = "defaultr";
  68. const string TRClass = "defaultr";
  69. const string TDHeaderClass = "header";
  70. const string TDDataClass = "content";
  71. //const string TDDataClassRight = "contentright";
  72. const string TDDataClassCenter = "contentcenter";
  73. const string STYLESHEET =
  74. @"
  75. <STYLE>
  76. body
  77. {
  78. font-size:15px; font-family:Helvetica, Verdana; color:Black;
  79. }
  80. TABLE.defaultr { }
  81. TR.defaultr { padding: 5px; }
  82. TD.header { font-weight:bold; padding:5px; }
  83. TD.content {}
  84. TD.contentright { text-align: right; }
  85. TD.contentcenter { text-align: center; }
  86. TD.align_top { vertical-align: top; }
  87. </STYLE>
  88. ";
  89. HTMLUtil.HtmlHeaders_O(ref output);
  90. HTMLUtil.InsertProtoTypeAJAX(ref output);
  91. string[] ajaxUpdaterDivs = new string[3];
  92. int[] ajaxUpdaterSeconds = new int[3];
  93. string[] ajaxUpdaterReportFragments = new string[3];
  94. ajaxUpdaterDivs[0] = "activeconnections";
  95. ajaxUpdaterSeconds[0] = 10;
  96. ajaxUpdaterReportFragments[0] = "activeconnectionsajax.html";
  97. ajaxUpdaterDivs[1] = "activesimstats";
  98. ajaxUpdaterSeconds[1] = 20;
  99. ajaxUpdaterReportFragments[1] = "simstatsajax.html";
  100. ajaxUpdaterDivs[2] = "activelog";
  101. ajaxUpdaterSeconds[2] = 5;
  102. ajaxUpdaterReportFragments[2] = "activelogajax.html";
  103. HTMLUtil.InsertPeriodicUpdaters(ref output, ajaxUpdaterDivs, ajaxUpdaterSeconds, ajaxUpdaterReportFragments);
  104. output.Append(STYLESHEET);
  105. HTMLUtil.HtmlHeaders_C(ref output);
  106. HTMLUtil.AddReportLinks(ref output, values.stats_reports, "");
  107. HTMLUtil.TABLE_O(ref output, TableClass);
  108. HTMLUtil.TR_O(ref output, TRClass);
  109. HTMLUtil.TD_O(ref output, TDHeaderClass);
  110. output.Append("# Users Total");
  111. HTMLUtil.TD_C(ref output);
  112. HTMLUtil.TD_O(ref output, TDHeaderClass);
  113. output.Append("# Sessions Total");
  114. HTMLUtil.TD_C(ref output);
  115. HTMLUtil.TD_O(ref output, TDHeaderClass);
  116. output.Append("Avg Client FPS");
  117. HTMLUtil.TD_C(ref output);
  118. HTMLUtil.TD_O(ref output, TDHeaderClass);
  119. output.Append("Avg Client Mem Use");
  120. HTMLUtil.TD_C(ref output);
  121. HTMLUtil.TD_O(ref output, TDHeaderClass);
  122. output.Append("Avg Sim FPS");
  123. HTMLUtil.TD_C(ref output);
  124. HTMLUtil.TD_O(ref output, TDHeaderClass);
  125. output.Append("Avg Ping");
  126. HTMLUtil.TD_C(ref output);
  127. HTMLUtil.TD_O(ref output, TDHeaderClass);
  128. output.Append("KB Out Total");
  129. HTMLUtil.TD_C(ref output);
  130. HTMLUtil.TD_O(ref output, TDHeaderClass);
  131. output.Append("KB In Total");
  132. HTMLUtil.TD_C(ref output);
  133. HTMLUtil.TR_C(ref output);
  134. HTMLUtil.TR_O(ref output, TRClass);
  135. HTMLUtil.TD_O(ref output, TDDataClass);
  136. output.Append(values.total_num_users);
  137. HTMLUtil.TD_C(ref output);
  138. HTMLUtil.TD_O(ref output, TDDataClass);
  139. output.Append(values.total_num_sessions);
  140. HTMLUtil.TD_C(ref output);
  141. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  142. output.Append(values.avg_client_fps);
  143. HTMLUtil.TD_C(ref output);
  144. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  145. output.Append(values.avg_client_mem_use);
  146. HTMLUtil.TD_C(ref output);
  147. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  148. output.Append(values.avg_sim_fps);
  149. HTMLUtil.TD_C(ref output);
  150. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  151. output.Append(values.avg_ping);
  152. HTMLUtil.TD_C(ref output);
  153. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  154. output.Append(values.total_kb_out);
  155. HTMLUtil.TD_C(ref output);
  156. HTMLUtil.TD_O(ref output, TDDataClassCenter);
  157. output.Append(values.total_kb_in);
  158. HTMLUtil.TD_C(ref output);
  159. HTMLUtil.TR_C(ref output);
  160. HTMLUtil.TABLE_C(ref output);
  161. HTMLUtil.HR(ref output, "");
  162. HTMLUtil.TABLE_O(ref output, "");
  163. HTMLUtil.TR_O(ref output, "");
  164. HTMLUtil.TD_O(ref output, "align_top");
  165. output.Append("<DIV id=\"activeconnections\">Active Connections loading...</DIV>");
  166. HTMLUtil.TD_C(ref output);
  167. HTMLUtil.TD_O(ref output, "align_top");
  168. output.Append("<DIV id=\"activesimstats\">SimStats loading...</DIV>");
  169. output.Append("<DIV id=\"activelog\">ActiveLog loading...</DIV>");
  170. HTMLUtil.TD_C(ref output);
  171. HTMLUtil.TR_C(ref output);
  172. HTMLUtil.TABLE_C(ref output);
  173. output.Append("</BODY></HTML>");
  174. // TODO: FIXME: template
  175. return output.ToString();
  176. }
  177. public stats_default_page_values rep_DefaultReport_data(SqliteConnection db, List<Scene> m_scene)
  178. {
  179. stats_default_page_values returnstruct = new stats_default_page_values();
  180. returnstruct.all_scenes = m_scene.ToArray();
  181. lock (db)
  182. {
  183. string SQL = @"SELECT COUNT(DISTINCT agent_id) as agents, COUNT(*) as sessions, AVG(avg_fps) as client_fps,
  184. AVG(avg_sim_fps) as savg_sim_fps, AVG(avg_ping) as sav_ping, SUM(n_out_kb) as num_in_kb,
  185. SUM(n_out_pk) as num_in_packets, SUM(n_in_kb) as num_out_kb, SUM(n_in_pk) as num_out_packets, AVG(mem_use) as sav_mem_use
  186. FROM stats_session_data;";
  187. SqliteCommand cmd = new SqliteCommand(SQL, db);
  188. SqliteDataReader sdr = cmd.ExecuteReader();
  189. if (sdr.HasRows)
  190. {
  191. sdr.Read();
  192. returnstruct.total_num_users = Convert.ToInt32(sdr["agents"]);
  193. returnstruct.total_num_sessions = Convert.ToInt32(sdr["sessions"]);
  194. returnstruct.avg_client_fps = Convert.ToSingle(sdr["client_fps"]);
  195. returnstruct.avg_sim_fps = Convert.ToSingle(sdr["savg_sim_fps"]);
  196. returnstruct.avg_ping = Convert.ToSingle(sdr["sav_ping"]);
  197. returnstruct.total_kb_out = Convert.ToSingle(sdr["num_out_kb"]);
  198. returnstruct.total_kb_in = Convert.ToSingle(sdr["num_in_kb"]);
  199. returnstruct.avg_client_mem_use = Convert.ToSingle(sdr["sav_mem_use"]);
  200. }
  201. }
  202. return returnstruct;
  203. }
  204. /// <summary>
  205. /// Return summar information in the form:
  206. /// <pre>
  207. /// {"totalUsers": "34",
  208. /// "totalSessions": "233",
  209. /// ...
  210. /// }
  211. /// </pre>
  212. /// </summary>
  213. /// <param name="pModelResult"></param>
  214. /// <returns></returns>
  215. public string RenderJson(Hashtable pModelResult) {
  216. stats_default_page_values values = (stats_default_page_values) pModelResult["hdata"];
  217. OSDMap summaryInfo = new OSDMap();
  218. summaryInfo.Add("totalUsers", new OSDString(values.total_num_users.ToString()));
  219. summaryInfo.Add("totalSessions", new OSDString(values.total_num_sessions.ToString()));
  220. summaryInfo.Add("averageClientFPS", new OSDString(values.avg_client_fps.ToString()));
  221. summaryInfo.Add("averageClientMem", new OSDString(values.avg_client_mem_use.ToString()));
  222. summaryInfo.Add("averageSimFPS", new OSDString(values.avg_sim_fps.ToString()));
  223. summaryInfo.Add("averagePingTime", new OSDString(values.avg_ping.ToString()));
  224. summaryInfo.Add("totalKBOut", new OSDString(values.total_kb_out.ToString()));
  225. summaryInfo.Add("totalKBIn", new OSDString(values.total_kb_in.ToString()));
  226. return summaryInfo.ToString();
  227. }
  228. }
  229. public struct stats_default_page_values
  230. {
  231. public int total_num_users;
  232. public int total_num_sessions;
  233. public float avg_client_fps;
  234. public float avg_client_mem_use;
  235. public float avg_sim_fps;
  236. public float avg_ping;
  237. public float total_kb_out;
  238. public float total_kb_in;
  239. public float avg_client_resends;
  240. public Scene[] all_scenes;
  241. public Dictionary<UUID, USimStatsData> sim_stat_data;
  242. public Dictionary<string, IStatsController> stats_reports;
  243. }
  244. }