diff options
author | Teravus Ovares | 2009-01-07 03:40:13 +0000 |
---|---|---|
committer | Teravus Ovares | 2009-01-07 03:40:13 +0000 |
commit | 9bd827a642c7178b9a0e0af103303c702cb40b64 (patch) | |
tree | dcb30a2a21f548847f28e7affb312074d5ee7f44 /OpenSim/Region/UserStatistics/Clients_report.cs | |
parent | * prune and regrade log messages relating to client login and logout (diff) | |
download | opensim-SC-9bd827a642c7178b9a0e0af103303c702cb40b64.zip opensim-SC-9bd827a642c7178b9a0e0af103303c702cb40b64.tar.gz opensim-SC-9bd827a642c7178b9a0e0af103303c702cb40b64.tar.bz2 opensim-SC-9bd827a642c7178b9a0e0af103303c702cb40b64.tar.xz |
* Added a client version report.
* Added a report-> link generator.
Diffstat (limited to 'OpenSim/Region/UserStatistics/Clients_report.cs')
-rw-r--r-- | OpenSim/Region/UserStatistics/Clients_report.cs | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/OpenSim/Region/UserStatistics/Clients_report.cs b/OpenSim/Region/UserStatistics/Clients_report.cs new file mode 100644 index 0000000..bc43e18 --- /dev/null +++ b/OpenSim/Region/UserStatistics/Clients_report.cs | |||
@@ -0,0 +1,299 @@ | |||
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 OpenSim.Region.Environment.Scenes; | ||
35 | |||
36 | namespace OpenSim.Region.UserStatistics | ||
37 | { | ||
38 | public class Clients_report : IStatsController | ||
39 | { | ||
40 | #region IStatsController Members | ||
41 | |||
42 | public string ReportName | ||
43 | { | ||
44 | get { return "Client"; } | ||
45 | } | ||
46 | |||
47 | public Hashtable ProcessModel(Hashtable pParams) | ||
48 | { | ||
49 | SqliteConnection dbConn = (SqliteConnection)pParams["DatabaseConnection"]; | ||
50 | |||
51 | |||
52 | List<ClientVersionData> clidata = new List<ClientVersionData>(); | ||
53 | List<ClientVersionData> cliRegData = new List<ClientVersionData>(); | ||
54 | Hashtable regionTotals = new Hashtable(); | ||
55 | |||
56 | Hashtable modeldata = new Hashtable(); | ||
57 | modeldata.Add("Scenes", pParams["Scenes"]); | ||
58 | modeldata.Add("Reports", pParams["Reports"]); | ||
59 | int totalclients = 0; | ||
60 | int totalregions = 0; | ||
61 | |||
62 | lock (dbConn) | ||
63 | { | ||
64 | string sql = "select count(distinct region_id) as regcnt from stats_session_data"; | ||
65 | |||
66 | SqliteCommand cmd = new SqliteCommand(sql, dbConn); | ||
67 | SqliteDataReader sdr = cmd.ExecuteReader(); | ||
68 | if (sdr.HasRows) | ||
69 | { | ||
70 | sdr.Read(); | ||
71 | totalregions = Convert.ToInt32(sdr["regcnt"]); | ||
72 | } | ||
73 | |||
74 | |||
75 | sql = | ||
76 | "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;"; | ||
77 | |||
78 | cmd = new SqliteCommand(sql, dbConn); | ||
79 | sdr = cmd.ExecuteReader(); | ||
80 | if (sdr.HasRows) | ||
81 | { | ||
82 | while (sdr.Read()) | ||
83 | { | ||
84 | ClientVersionData udata = new ClientVersionData(); | ||
85 | udata.version = sdr["client_version"].ToString(); | ||
86 | udata.count = Convert.ToInt32(sdr["cnt"]); | ||
87 | udata.fps = Convert.ToSingle(sdr["simfps"]); | ||
88 | clidata.Add(udata); | ||
89 | totalclients += udata.count; | ||
90 | |||
91 | } | ||
92 | } | ||
93 | sdr.Close(); | ||
94 | sdr.Dispose(); | ||
95 | |||
96 | if (totalregions > 1) | ||
97 | { | ||
98 | sql = | ||
99 | "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;"; | ||
100 | cmd = new SqliteCommand(sql, dbConn); | ||
101 | |||
102 | sdr = cmd.ExecuteReader(); | ||
103 | |||
104 | if (sdr.HasRows) | ||
105 | { | ||
106 | while (sdr.Read()) | ||
107 | { | ||
108 | ClientVersionData udata = new ClientVersionData(); | ||
109 | udata.version = sdr["client_version"].ToString(); | ||
110 | udata.count = Convert.ToInt32(sdr["cnt"]); | ||
111 | udata.fps = Convert.ToSingle(sdr["simfps"]); | ||
112 | udata.region_id = UUID.Parse(sdr["region_id"].ToString()); | ||
113 | cliRegData.Add(udata); | ||
114 | } | ||
115 | } | ||
116 | sdr.Close(); | ||
117 | sdr.Dispose(); | ||
118 | |||
119 | |||
120 | } | ||
121 | |||
122 | } | ||
123 | |||
124 | foreach (ClientVersionData cvd in cliRegData) | ||
125 | { | ||
126 | |||
127 | if (regionTotals.ContainsKey(cvd.region_id)) | ||
128 | { | ||
129 | int regiontotal = (int)regionTotals[cvd.region_id]; | ||
130 | regiontotal += cvd.count; | ||
131 | regionTotals[cvd.region_id] = regiontotal; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | regionTotals.Add(cvd.region_id, cvd.count); | ||
136 | } | ||
137 | |||
138 | |||
139 | |||
140 | } | ||
141 | |||
142 | modeldata["ClientData"] = clidata; | ||
143 | modeldata["ClientRegionData"] = cliRegData; | ||
144 | modeldata["RegionTotals"] = regionTotals; | ||
145 | modeldata["Total"] = totalclients; | ||
146 | |||
147 | return modeldata; | ||
148 | } | ||
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 | |||
159 | const string STYLESHEET = | ||
160 | @" | ||
161 | <STYLE> | ||
162 | body | ||
163 | { | ||
164 | font-size:15px; font-family:Helvetica, Verdana; color:Black; | ||
165 | } | ||
166 | TABLE.defaultr { } | ||
167 | TR.defaultr { padding: 5px; } | ||
168 | TD.header { font-weight:bold; padding:5px; } | ||
169 | TD.content {} | ||
170 | TD.contentright { text-align: right; } | ||
171 | TD.contentcenter { text-align: center; } | ||
172 | TD.align_top { vertical-align: top; } | ||
173 | </STYLE> | ||
174 | "; | ||
175 | |||
176 | StringBuilder output = new StringBuilder(); | ||
177 | HTMLUtil.HtmlHeaders_O(ref output); | ||
178 | output.Append(STYLESHEET); | ||
179 | HTMLUtil.HtmlHeaders_C(ref output); | ||
180 | |||
181 | HTMLUtil.AddReportLinks(ref output, reports, ""); | ||
182 | |||
183 | HTMLUtil.TABLE_O(ref output, "defaultr"); | ||
184 | HTMLUtil.TR_O(ref output, ""); | ||
185 | HTMLUtil.TD_O(ref output, "header"); | ||
186 | output.Append("ClientVersion"); | ||
187 | HTMLUtil.TD_C(ref output); | ||
188 | HTMLUtil.TD_O(ref output, "header"); | ||
189 | output.Append("Count/%"); | ||
190 | HTMLUtil.TD_C(ref output); | ||
191 | HTMLUtil.TD_O(ref output, "header"); | ||
192 | output.Append("SimFPS"); | ||
193 | HTMLUtil.TD_C(ref output); | ||
194 | HTMLUtil.TR_C(ref output); | ||
195 | |||
196 | foreach (ClientVersionData cvd in clidata) | ||
197 | { | ||
198 | HTMLUtil.TR_O(ref output, ""); | ||
199 | HTMLUtil.TD_O(ref output, "content"); | ||
200 | output.Append(cvd.version); | ||
201 | HTMLUtil.TD_C(ref output); | ||
202 | HTMLUtil.TD_O(ref output, "content"); | ||
203 | output.Append(cvd.count); | ||
204 | output.Append("/"); | ||
205 | if (totalclients > 0) | ||
206 | output.Append((((float)cvd.count / (float)totalclients)*100).ToString()); | ||
207 | else | ||
208 | output.Append(0); | ||
209 | |||
210 | output.Append("%"); | ||
211 | HTMLUtil.TD_C(ref output); | ||
212 | HTMLUtil.TD_O(ref output, "content"); | ||
213 | output.Append(cvd.fps); | ||
214 | HTMLUtil.TD_C(ref output); | ||
215 | HTMLUtil.TR_C(ref output); | ||
216 | } | ||
217 | HTMLUtil.TABLE_C(ref output); | ||
218 | |||
219 | if (cliRegData.Count > 0) | ||
220 | { | ||
221 | HTMLUtil.TABLE_O(ref output, "defaultr"); | ||
222 | HTMLUtil.TR_O(ref output, ""); | ||
223 | HTMLUtil.TD_O(ref output, "header"); | ||
224 | output.Append("Region"); | ||
225 | HTMLUtil.TD_C(ref output); | ||
226 | HTMLUtil.TD_O(ref output, "header"); | ||
227 | output.Append("ClientVersion"); | ||
228 | HTMLUtil.TD_C(ref output); | ||
229 | HTMLUtil.TD_O(ref output, "header"); | ||
230 | output.Append("Count/%"); | ||
231 | HTMLUtil.TD_C(ref output); | ||
232 | HTMLUtil.TD_O(ref output, "header"); | ||
233 | output.Append("SimFPS"); | ||
234 | HTMLUtil.TD_C(ref output); | ||
235 | HTMLUtil.TR_C(ref output); | ||
236 | |||
237 | foreach (ClientVersionData cvd in cliRegData) | ||
238 | { | ||
239 | HTMLUtil.TR_O(ref output, ""); | ||
240 | HTMLUtil.TD_O(ref output, "content"); | ||
241 | output.Append(regionNamefromUUID(m_scenes, cvd.region_id)); | ||
242 | HTMLUtil.TD_C(ref output); | ||
243 | HTMLUtil.TD_O(ref output, "content"); | ||
244 | output.Append(cvd.version); | ||
245 | HTMLUtil.TD_C(ref output); | ||
246 | HTMLUtil.TD_O(ref output, "content"); | ||
247 | output.Append(cvd.count); | ||
248 | output.Append("/"); | ||
249 | if ((int)regionTotals[cvd.region_id] > 0) | ||
250 | output.Append((((float)cvd.count / (float)((int)regionTotals[cvd.region_id])) * 100).ToString()); | ||
251 | else | ||
252 | output.Append(0); | ||
253 | |||
254 | output.Append("%"); | ||
255 | HTMLUtil.TD_C(ref output); | ||
256 | HTMLUtil.TD_O(ref output, "content"); | ||
257 | output.Append(cvd.fps); | ||
258 | HTMLUtil.TD_C(ref output); | ||
259 | HTMLUtil.TR_C(ref output); | ||
260 | } | ||
261 | HTMLUtil.TABLE_C(ref output); | ||
262 | |||
263 | } | ||
264 | |||
265 | output.Append("</BODY>"); | ||
266 | output.Append("</HTML>"); | ||
267 | return output.ToString(); | ||
268 | } | ||
269 | public string regionNamefromUUID(List<Scene> scenes, UUID region_id) | ||
270 | { | ||
271 | string returnstring = string.Empty; | ||
272 | foreach (Scene sn in scenes) | ||
273 | { | ||
274 | if (region_id == sn.RegionInfo.originRegionID) | ||
275 | { | ||
276 | returnstring = sn.RegionInfo.RegionName; | ||
277 | break; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | if (returnstring.Length == 0) | ||
282 | { | ||
283 | returnstring = region_id.ToString(); | ||
284 | } | ||
285 | |||
286 | return returnstring; | ||
287 | } | ||
288 | |||
289 | #endregion | ||
290 | } | ||
291 | |||
292 | public struct ClientVersionData | ||
293 | { | ||
294 | public UUID region_id; | ||
295 | public string version; | ||
296 | public int count; | ||
297 | public float fps; | ||
298 | } | ||
299 | } | ||