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