aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Monitoring/Stats
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Monitoring/Stats')
-rwxr-xr-xOpenSim/Framework/Monitoring/Stats/CounterStat.cs21
-rw-r--r--OpenSim/Framework/Monitoring/Stats/Stat.cs47
2 files changed, 64 insertions, 4 deletions
diff --git a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
index caea30d..04442c3 100755
--- a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
@@ -224,5 +224,26 @@ public class CounterStat : Stat
224 } 224 }
225 } 225 }
226 } 226 }
227
228 // CounterStat is a basic stat plus histograms
229 public override OSDMap ToOSDMap()
230 {
231 // Get the foundational instance
232 OSDMap map = base.ToOSDMap();
233
234 map["StatType"] = "CounterStat";
235
236 // If there are any histograms, add a new field that is an array of histograms as OSDMaps
237 if (m_histograms.Count > 0)
238 {
239 OSDArray histos = new OSDArray();
240 foreach (EventHistogram histo in m_histograms.Values)
241 {
242 histos.Add(histo.GetHistogramAsOSDMap());
243 }
244 map.Add("Histograms", histos);
245 }
246 return map;
247 }
227} 248}
228} 249}
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 2e7665f..ffd5132 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -27,8 +27,10 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
30using System.Text; 32using System.Text;
31 33using log4net;
32using OpenMetaverse.StructuredData; 34using OpenMetaverse.StructuredData;
33 35
34namespace OpenSim.Framework.Monitoring 36namespace OpenSim.Framework.Monitoring
@@ -38,6 +40,10 @@ namespace OpenSim.Framework.Monitoring
38 /// </summary> 40 /// </summary>
39 public class Stat : IDisposable 41 public class Stat : IDisposable
40 { 42 {
43// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 public static readonly char[] DisallowedShortNameCharacters = { '.' };
46
41 /// <summary> 47 /// <summary>
42 /// Category of this stat (e.g. cache, scene, etc). 48 /// Category of this stat (e.g. cache, scene, etc).
43 /// </summary> 49 /// </summary>
@@ -95,7 +101,7 @@ namespace OpenSim.Framework.Monitoring
95 /// <remarks> 101 /// <remarks>
96 /// Will be null if no measures of interest require samples. 102 /// Will be null if no measures of interest require samples.
97 /// </remarks> 103 /// </remarks>
98 private static Queue<double> m_samples; 104 private Queue<double> m_samples;
99 105
100 /// <summary> 106 /// <summary>
101 /// Maximum number of statistical samples. 107 /// Maximum number of statistical samples.
@@ -162,6 +168,12 @@ namespace OpenSim.Framework.Monitoring
162 throw new Exception( 168 throw new Exception(
163 string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); 169 string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category));
164 170
171 foreach (char c in DisallowedShortNameCharacters)
172 {
173 if (shortName.IndexOf(c) != -1)
174 throw new Exception(string.Format("Stat name {0} cannot contain character {1}", shortName, c));
175 }
176
165 ShortName = shortName; 177 ShortName = shortName;
166 Name = name; 178 Name = name;
167 Description = description; 179 Description = description;
@@ -204,6 +216,8 @@ namespace OpenSim.Framework.Monitoring
204 if (m_samples.Count >= m_maxSamples) 216 if (m_samples.Count >= m_maxSamples)
205 m_samples.Dequeue(); 217 m_samples.Dequeue();
206 218
219// m_log.DebugFormat("[STAT]: Recording value {0} for {1}", newValue, Name);
220
207 m_samples.Enqueue(newValue); 221 m_samples.Enqueue(newValue);
208 } 222 }
209 } 223 }
@@ -211,7 +225,13 @@ namespace OpenSim.Framework.Monitoring
211 public virtual string ToConsoleString() 225 public virtual string ToConsoleString()
212 { 226 {
213 StringBuilder sb = new StringBuilder(); 227 StringBuilder sb = new StringBuilder();
214 sb.AppendFormat("{0}.{1}.{2} : {3} {4}", Category, Container, ShortName, Value, UnitName); 228 sb.AppendFormat(
229 "{0}.{1}.{2} : {3}{4}",
230 Category,
231 Container,
232 ShortName,
233 Value,
234 UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
215 235
216 AppendMeasuresOfInterest(sb); 236 AppendMeasuresOfInterest(sb);
217 237
@@ -228,6 +248,7 @@ namespace OpenSim.Framework.Monitoring
228 ret.Add("Description", OSD.FromString(Description)); 248 ret.Add("Description", OSD.FromString(Description));
229 ret.Add("UnitName", OSD.FromString(UnitName)); 249 ret.Add("UnitName", OSD.FromString(UnitName));
230 ret.Add("Value", OSD.FromReal(Value)); 250 ret.Add("Value", OSD.FromReal(Value));
251 ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat
231 252
232 return ret; 253 return ret;
233 } 254 }
@@ -238,22 +259,40 @@ namespace OpenSim.Framework.Monitoring
238 == MeasuresOfInterest.AverageChangeOverTime) 259 == MeasuresOfInterest.AverageChangeOverTime)
239 { 260 {
240 double totalChange = 0; 261 double totalChange = 0;
262 double lastChangeOverTime = 0;
263 double? penultimateSample = null;
241 double? lastSample = null; 264 double? lastSample = null;
242 265
243 lock (m_samples) 266 lock (m_samples)
244 { 267 {
268// m_log.DebugFormat(
269// "[STAT]: Samples for {0} are {1}",
270// Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray()));
271
245 foreach (double s in m_samples) 272 foreach (double s in m_samples)
246 { 273 {
247 if (lastSample != null) 274 if (lastSample != null)
248 totalChange += s - (double)lastSample; 275 totalChange += s - (double)lastSample;
249 276
277 penultimateSample = lastSample;
250 lastSample = s; 278 lastSample = s;
251 } 279 }
252 } 280 }
253 281
282 if (lastSample != null && penultimateSample != null)
283 lastChangeOverTime
284 = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
285
254 int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; 286 int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1;
255 287
256 sb.AppendFormat(", {0:0.##}{1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName); 288 double averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
289
290 sb.AppendFormat(
291 ", {0:0.##}{1}/s, {2:0.##}{3}/s",
292 lastChangeOverTime,
293 UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName),
294 averageChangeOverTime,
295 UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
257 } 296 }
258 } 297 }
259 } 298 }