Default_Report.cs 10 KB

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