Clients_report.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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.Text;
  31. using Mono.Data.SqliteClient;
  32. using OpenMetaverse;
  33. using OpenMetaverse.StructuredData;
  34. using OpenSim.Region.Framework.Scenes;
  35. namespace OpenSim.Region.UserStatistics
  36. {
  37. public class Clients_report : IStatsController
  38. {
  39. #region IStatsController Members
  40. public string ReportName
  41. {
  42. get { return "Client"; }
  43. }
  44. /// <summary>
  45. /// Return summar information in the form:
  46. /// <pre>
  47. /// {"totalUsers": "34",
  48. /// "totalSessions": "233",
  49. /// ...
  50. /// }
  51. /// </pre>
  52. /// </summary>
  53. /// <param name="pModelResult"></param>
  54. /// <returns></returns>
  55. public string RenderJson(Hashtable pModelResult) {
  56. stats_default_page_values values = (stats_default_page_values) pModelResult["hdata"];
  57. OSDMap summaryInfo = new OpenMetaverse.StructuredData.OSDMap();
  58. summaryInfo.Add("totalUsers", new OSDString(values.total_num_users.ToString()));
  59. summaryInfo.Add("totalSessions", new OSDString(values.total_num_sessions.ToString()));
  60. summaryInfo.Add("averageClientFPS", new OSDString(values.avg_client_fps.ToString()));
  61. summaryInfo.Add("averageClientMem", new OSDString(values.avg_client_mem_use.ToString()));
  62. summaryInfo.Add("averageSimFPS", new OSDString(values.avg_sim_fps.ToString()));
  63. summaryInfo.Add("averagePingTime", new OSDString(values.avg_ping.ToString()));
  64. summaryInfo.Add("totalKBOut", new OSDString(values.total_kb_out.ToString()));
  65. summaryInfo.Add("totalKBIn", new OSDString(values.total_kb_in.ToString()));
  66. return summaryInfo.ToString();
  67. }
  68. public Hashtable ProcessModel(Hashtable pParams)
  69. {
  70. SqliteConnection dbConn = (SqliteConnection)pParams["DatabaseConnection"];
  71. List<ClientVersionData> clidata = new List<ClientVersionData>();
  72. List<ClientVersionData> cliRegData = new List<ClientVersionData>();
  73. Hashtable regionTotals = new Hashtable();
  74. Hashtable modeldata = new Hashtable();
  75. modeldata.Add("Scenes", pParams["Scenes"]);
  76. modeldata.Add("Reports", pParams["Reports"]);
  77. int totalclients = 0;
  78. int totalregions = 0;
  79. lock (dbConn)
  80. {
  81. string sql = "select count(distinct region_id) as regcnt from stats_session_data";
  82. SqliteCommand cmd = new SqliteCommand(sql, dbConn);
  83. SqliteDataReader sdr = cmd.ExecuteReader();
  84. if (sdr.HasRows)
  85. {
  86. sdr.Read();
  87. totalregions = Convert.ToInt32(sdr["regcnt"]);
  88. }
  89. sdr.Close();
  90. cmd.Dispose();
  91. sql =
  92. "select client_version, count(*) as cnt, avg(avg_sim_fps) as simfps from stats_session_data group by client_version order by count(*) desc LIMIT 10;";
  93. cmd = new SqliteCommand(sql, dbConn);
  94. sdr = cmd.ExecuteReader();
  95. if (sdr.HasRows)
  96. {
  97. while (sdr.Read())
  98. {
  99. ClientVersionData udata = new ClientVersionData();
  100. udata.version = sdr["client_version"].ToString();
  101. udata.count = Convert.ToInt32(sdr["cnt"]);
  102. udata.fps = Convert.ToSingle(sdr["simfps"]);
  103. clidata.Add(udata);
  104. totalclients += udata.count;
  105. }
  106. }
  107. sdr.Close();
  108. cmd.Dispose();
  109. if (totalregions > 1)
  110. {
  111. sql =
  112. "select region_id, client_version, count(*) as cnt, avg(avg_sim_fps) as simfps from stats_session_data group by region_id, client_version order by region_id, count(*) desc;";
  113. cmd = new SqliteCommand(sql, dbConn);
  114. sdr = cmd.ExecuteReader();
  115. if (sdr.HasRows)
  116. {
  117. while (sdr.Read())
  118. {
  119. ClientVersionData udata = new ClientVersionData();
  120. udata.version = sdr["client_version"].ToString();
  121. udata.count = Convert.ToInt32(sdr["cnt"]);
  122. udata.fps = Convert.ToSingle(sdr["simfps"]);
  123. udata.region_id = UUID.Parse(sdr["region_id"].ToString());
  124. cliRegData.Add(udata);
  125. }
  126. }
  127. sdr.Close();
  128. cmd.Dispose();
  129. }
  130. }
  131. foreach (ClientVersionData cvd in cliRegData)
  132. {
  133. if (regionTotals.ContainsKey(cvd.region_id))
  134. {
  135. int regiontotal = (int)regionTotals[cvd.region_id];
  136. regiontotal += cvd.count;
  137. regionTotals[cvd.region_id] = regiontotal;
  138. }
  139. else
  140. {
  141. regionTotals.Add(cvd.region_id, cvd.count);
  142. }
  143. }
  144. modeldata["ClientData"] = clidata;
  145. modeldata["ClientRegionData"] = cliRegData;
  146. modeldata["RegionTotals"] = regionTotals;
  147. modeldata["Total"] = totalclients;
  148. return modeldata;
  149. }
  150. public string RenderView(Hashtable pModelResult)
  151. {
  152. List<ClientVersionData> clidata = (List<ClientVersionData>) pModelResult["ClientData"];
  153. int totalclients = (int)pModelResult["Total"];
  154. Hashtable regionTotals = (Hashtable) pModelResult["RegionTotals"];
  155. List<ClientVersionData> cliRegData = (List<ClientVersionData>) pModelResult["ClientRegionData"];
  156. List<Scene> m_scenes = (List<Scene>)pModelResult["Scenes"];
  157. Dictionary<string, IStatsController> reports = (Dictionary<string, IStatsController>)pModelResult["Reports"];
  158. const string STYLESHEET =
  159. @"
  160. <STYLE>
  161. body
  162. {
  163. font-size:15px; font-family:Helvetica, Verdana; color:Black;
  164. }
  165. TABLE.defaultr { }
  166. TR.defaultr { padding: 5px; }
  167. TD.header { font-weight:bold; padding:5px; }
  168. TD.content {}
  169. TD.contentright { text-align: right; }
  170. TD.contentcenter { text-align: center; }
  171. TD.align_top { vertical-align: top; }
  172. </STYLE>
  173. ";
  174. StringBuilder output = new StringBuilder();
  175. HTMLUtil.HtmlHeaders_O(ref output);
  176. output.Append(STYLESHEET);
  177. HTMLUtil.HtmlHeaders_C(ref output);
  178. HTMLUtil.AddReportLinks(ref output, reports, "");
  179. HTMLUtil.TABLE_O(ref output, "defaultr");
  180. HTMLUtil.TR_O(ref output, "");
  181. HTMLUtil.TD_O(ref output, "header");
  182. output.Append("ClientVersion");
  183. HTMLUtil.TD_C(ref output);
  184. HTMLUtil.TD_O(ref output, "header");
  185. output.Append("Count/%");
  186. HTMLUtil.TD_C(ref output);
  187. HTMLUtil.TD_O(ref output, "header");
  188. output.Append("SimFPS");
  189. HTMLUtil.TD_C(ref output);
  190. HTMLUtil.TR_C(ref output);
  191. foreach (ClientVersionData cvd in clidata)
  192. {
  193. HTMLUtil.TR_O(ref output, "");
  194. HTMLUtil.TD_O(ref output, "content");
  195. string linkhref = "sessions.report?VersionString=" + cvd.version;
  196. HTMLUtil.A(ref output, cvd.version, linkhref, "");
  197. HTMLUtil.TD_C(ref output);
  198. HTMLUtil.TD_O(ref output, "content");
  199. output.Append(cvd.count);
  200. output.Append("/");
  201. if (totalclients > 0)
  202. output.Append((((float)cvd.count / (float)totalclients)*100).ToString());
  203. else
  204. output.Append(0);
  205. output.Append("%");
  206. HTMLUtil.TD_C(ref output);
  207. HTMLUtil.TD_O(ref output, "content");
  208. output.Append(cvd.fps);
  209. HTMLUtil.TD_C(ref output);
  210. HTMLUtil.TR_C(ref output);
  211. }
  212. HTMLUtil.TABLE_C(ref output);
  213. if (cliRegData.Count > 0)
  214. {
  215. HTMLUtil.TABLE_O(ref output, "defaultr");
  216. HTMLUtil.TR_O(ref output, "");
  217. HTMLUtil.TD_O(ref output, "header");
  218. output.Append("Region");
  219. HTMLUtil.TD_C(ref output);
  220. HTMLUtil.TD_O(ref output, "header");
  221. output.Append("ClientVersion");
  222. HTMLUtil.TD_C(ref output);
  223. HTMLUtil.TD_O(ref output, "header");
  224. output.Append("Count/%");
  225. HTMLUtil.TD_C(ref output);
  226. HTMLUtil.TD_O(ref output, "header");
  227. output.Append("SimFPS");
  228. HTMLUtil.TD_C(ref output);
  229. HTMLUtil.TR_C(ref output);
  230. foreach (ClientVersionData cvd in cliRegData)
  231. {
  232. HTMLUtil.TR_O(ref output, "");
  233. HTMLUtil.TD_O(ref output, "content");
  234. output.Append(regionNamefromUUID(m_scenes, cvd.region_id));
  235. HTMLUtil.TD_C(ref output);
  236. HTMLUtil.TD_O(ref output, "content");
  237. output.Append(cvd.version);
  238. HTMLUtil.TD_C(ref output);
  239. HTMLUtil.TD_O(ref output, "content");
  240. output.Append(cvd.count);
  241. output.Append("/");
  242. if ((int)regionTotals[cvd.region_id] > 0)
  243. output.Append((((float)cvd.count / (float)((int)regionTotals[cvd.region_id])) * 100).ToString());
  244. else
  245. output.Append(0);
  246. output.Append("%");
  247. HTMLUtil.TD_C(ref output);
  248. HTMLUtil.TD_O(ref output, "content");
  249. output.Append(cvd.fps);
  250. HTMLUtil.TD_C(ref output);
  251. HTMLUtil.TR_C(ref output);
  252. }
  253. HTMLUtil.TABLE_C(ref output);
  254. }
  255. output.Append("</BODY>");
  256. output.Append("</HTML>");
  257. return output.ToString();
  258. }
  259. public string regionNamefromUUID(List<Scene> scenes, UUID region_id)
  260. {
  261. string returnstring = string.Empty;
  262. foreach (Scene sn in scenes)
  263. {
  264. if (region_id == sn.RegionInfo.originRegionID)
  265. {
  266. returnstring = sn.RegionInfo.RegionName;
  267. break;
  268. }
  269. }
  270. if (returnstring.Length == 0)
  271. {
  272. returnstring = region_id.ToString();
  273. }
  274. return returnstring;
  275. }
  276. #endregion
  277. }
  278. public struct ClientVersionData
  279. {
  280. public UUID region_id;
  281. public string version;
  282. public int count;
  283. public float fps;
  284. }
  285. }