29 using System.Collections.Generic;
31 using System.Reflection;
36 using OpenMetaverse.Packets;
37 using OpenSim.Framework;
38 using OpenSim.Region.Framework;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
44 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"BinaryLoggingModule")]
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 public string Name {
get {
return "Binary Statistics Logging Module"; } }
53 public Type ReplaceableInterface {
get {
return null; } }
59 IConfig statConfig = source.Configs[
"Statistics.Binary"];
60 if (statConfig != null && statConfig.Contains(
"enabled") && statConfig.GetBoolean(
"enabled"))
62 if (statConfig.Contains(
"collect_region_stats"))
64 if (statConfig.GetBoolean(
"collect_region_stats"))
66 m_collectStats =
true;
69 if (statConfig.Contains(
"region_stats_period_seconds"))
71 m_statLogPeriod = TimeSpan.FromSeconds(statConfig.GetInt(
"region_stats_period_seconds"));
73 if (statConfig.Contains(
"stats_dir"))
75 m_statsDir = statConfig.GetString(
"stats_dir");
97 m_scene.StatsReporter.OnSendStatsResult += LogSimStats;
108 public System.IO.BinaryWriter
Log;
112 static TimeSpan m_statLogPeriod = TimeSpan.FromSeconds(300);
113 static string m_statsDir = String.Empty;
116 private void LogSimStats(
SimStats stats)
118 SimStatsPacket pack =
new SimStatsPacket();
119 pack.Region =
new SimStatsPacket.RegionBlock();
120 pack.Region.RegionX = stats.RegionX;
121 pack.Region.RegionY = stats.RegionY;
123 pack.Region.ObjectCapacity = stats.ObjectCapacity;
125 pack.Stat = stats.StatsBlock;
126 pack.Header.Reliable =
false;
129 DateTime now = DateTime.Now;
132 pack.Header.Sequence = (uint)now.Ticks;
134 lock (m_statLockObject)
138 if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod)
141 if (m_statLog != null && m_statLog.Log != null)
143 m_statLog.Log.Close();
145 m_statLog =
new StatLogger();
146 m_statLog.StartTime = now;
147 m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() :
"")
148 + String.Format(
"stats-{0}.log", now.ToString(
"yyyyMMddHHmmss"));
149 m_statLog.Log =
new BinaryWriter(
File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write));
153 if (m_statLog != null && m_statLog.Log != null)
154 m_statLog.Log.Write(pack.ToBytes());
158 m_log.Error(
"statistics gathering failed: " + ex.Message, ex);
159 if (m_statLog != null && m_statLog.Log != null)
161 m_statLog.Log.Close();
System.IO.BinaryWriter Log
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
Enapsulate statistics for a simulator/scene.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
RegionFlags
Region flags used internally by OpenSimulator to store installation specific information about region...
Interactive OpenSim region server