opensim-development – Blame information for rev 1

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