diff options
author | Justin Clark-Casey (justincc) | 2010-08-13 23:15:11 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-08-13 23:15:11 +0100 |
commit | ab6dc478188e1609d9656e65d410d08270066bf0 (patch) | |
tree | 0793c17d0a88fa911740b6a04a3db25780b72641 /OpenSim | |
parent | refactor: move Scene.PerformObjectBuy into BuySellModule (diff) | |
download | opensim-SC_OLD-ab6dc478188e1609d9656e65d410d08270066bf0.zip opensim-SC_OLD-ab6dc478188e1609d9656e65d410d08270066bf0.tar.gz opensim-SC_OLD-ab6dc478188e1609d9656e65d410d08270066bf0.tar.bz2 opensim-SC_OLD-ab6dc478188e1609d9656e65d410d08270066bf0.tar.xz |
refactor: move binary statistics logging from scene into separate region module
Diffstat (limited to 'OpenSim')
3 files changed, 181 insertions, 110 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs new file mode 100644 index 0000000..b75a700 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs | |||
@@ -0,0 +1,169 @@ | |||
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.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
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; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Avatar.Attachments | ||
43 | { | ||
44 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BinaryLoggingModule")] | ||
45 | public class BinaryLoggingModule : INonSharedRegionModule | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected bool m_collectStats; | ||
50 | protected Scene m_scene = null; | ||
51 | |||
52 | public string Name { get { return "Binary Statistics Logging Module"; } } | ||
53 | public Type ReplaceableInterface { get { return null; } } | ||
54 | |||
55 | public void Initialise(IConfigSource source) | ||
56 | { | ||
57 | try | ||
58 | { | ||
59 | IConfig statConfig = source.Configs["Statistics.Binary"]; | ||
60 | if (statConfig.Contains("enabled") && statConfig.GetBoolean("enabled")) | ||
61 | { | ||
62 | if (statConfig.Contains("collect_region_stats")) | ||
63 | { | ||
64 | if (statConfig.GetBoolean("collect_region_stats")) | ||
65 | { | ||
66 | m_collectStats = true; | ||
67 | } | ||
68 | } | ||
69 | if (statConfig.Contains("region_stats_period_seconds")) | ||
70 | { | ||
71 | m_statLogPeriod = TimeSpan.FromSeconds(statConfig.GetInt("region_stats_period_seconds")); | ||
72 | } | ||
73 | if (statConfig.Contains("stats_dir")) | ||
74 | { | ||
75 | m_statsDir = statConfig.GetString("stats_dir"); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | catch | ||
80 | { | ||
81 | // if it doesn't work, we don't collect anything | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public void AddRegion(Scene scene) | ||
86 | { | ||
87 | m_scene = scene; | ||
88 | } | ||
89 | |||
90 | public void RemoveRegion(Scene scene) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene scene) | ||
95 | { | ||
96 | if (m_collectStats) | ||
97 | m_scene.StatsReporter.OnSendStatsResult += LogSimStats; | ||
98 | } | ||
99 | |||
100 | public void Close() | ||
101 | { | ||
102 | } | ||
103 | |||
104 | public class StatLogger | ||
105 | { | ||
106 | public DateTime StartTime; | ||
107 | public string Path; | ||
108 | public System.IO.BinaryWriter Log; | ||
109 | } | ||
110 | |||
111 | static StatLogger m_statLog = null; | ||
112 | static TimeSpan m_statLogPeriod = TimeSpan.FromSeconds(300); | ||
113 | static string m_statsDir = String.Empty; | ||
114 | static Object m_statLockObject = new Object(); | ||
115 | |||
116 | private void LogSimStats(SimStats stats) | ||
117 | { | ||
118 | SimStatsPacket pack = new SimStatsPacket(); | ||
119 | pack.Region = new SimStatsPacket.RegionBlock(); | ||
120 | pack.Region.RegionX = stats.RegionX; | ||
121 | pack.Region.RegionY = stats.RegionY; | ||
122 | pack.Region.RegionFlags = stats.RegionFlags; | ||
123 | pack.Region.ObjectCapacity = stats.ObjectCapacity; | ||
124 | //pack.Region = //stats.RegionBlock; | ||
125 | pack.Stat = stats.StatsBlock; | ||
126 | pack.Header.Reliable = false; | ||
127 | |||
128 | // note that we are inside the reporter lock when called | ||
129 | DateTime now = DateTime.Now; | ||
130 | |||
131 | // hide some time information into the packet | ||
132 | pack.Header.Sequence = (uint)now.Ticks; | ||
133 | |||
134 | lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here | ||
135 | { | ||
136 | try | ||
137 | { | ||
138 | if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod) | ||
139 | { | ||
140 | // First log file or time has expired, start writing to a new log file | ||
141 | if (m_statLog != null && m_statLog.Log != null) | ||
142 | { | ||
143 | m_statLog.Log.Close(); | ||
144 | } | ||
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)); | ||
150 | } | ||
151 | |||
152 | // Write the serialized data to disk | ||
153 | if (m_statLog != null && m_statLog.Log != null) | ||
154 | m_statLog.Log.Write(pack.ToBytes()); | ||
155 | } | ||
156 | catch (Exception ex) | ||
157 | { | ||
158 | m_log.Error("statistics gathering failed: " + ex.Message, ex); | ||
159 | if (m_statLog != null && m_statLog.Log != null) | ||
160 | { | ||
161 | m_statLog.Log.Close(); | ||
162 | } | ||
163 | m_statLog = null; | ||
164 | } | ||
165 | } | ||
166 | return; | ||
167 | } | ||
168 | } | ||
169 | } | ||
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 4f5a65e..9963225 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -834,7 +834,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
834 | ScenePresence presence; | 834 | ScenePresence presence; |
835 | if (TryGetScenePresence(remoteClient.AgentId, out presence)) | 835 | if (TryGetScenePresence(remoteClient.AgentId, out presence)) |
836 | { | 836 | { |
837 | byte[] data = null; | 837 | // byte[] data = null; |
838 | 838 | ||
839 | AssetBase asset = new AssetBase(); | 839 | AssetBase asset = new AssetBase(); |
840 | asset.FullID = olditemID; | 840 | asset.FullID = olditemID; |
@@ -842,8 +842,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
842 | asset.Name = name; | 842 | asset.Name = name; |
843 | asset.Description = description; | 843 | asset.Description = description; |
844 | 844 | ||
845 | CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, name, 0, callbackID, asset, invType, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch()); | 845 | CreateNewInventoryItem( |
846 | 846 | remoteClient, remoteClient.AgentId.ToString(), folderID, name, 0, callbackID, asset, invType, | |
847 | (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, | ||
848 | (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch()); | ||
847 | } | 849 | } |
848 | else | 850 | else |
849 | { | 851 | { |
@@ -876,7 +878,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
876 | InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs); | 878 | InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs); |
877 | } | 879 | } |
878 | 880 | ||
879 | |||
880 | /// <summary> | 881 | /// <summary> |
881 | /// Send the details of a prim's inventory to the client. | 882 | /// Send the details of a prim's inventory to the client. |
882 | /// </summary> | 883 | /// </summary> |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 5f6748e..f62851a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -481,73 +481,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
481 | 481 | ||
482 | #endregion | 482 | #endregion |
483 | 483 | ||
484 | #region BinaryStats | ||
485 | |||
486 | public class StatLogger | ||
487 | { | ||
488 | public DateTime StartTime; | ||
489 | public string Path; | ||
490 | public System.IO.BinaryWriter Log; | ||
491 | } | ||
492 | static StatLogger m_statLog = null; | ||
493 | static TimeSpan m_statLogPeriod = TimeSpan.FromSeconds(300); | ||
494 | static string m_statsDir = String.Empty; | ||
495 | static Object m_statLockObject = new Object(); | ||
496 | private void LogSimStats(SimStats stats) | ||
497 | { | ||
498 | SimStatsPacket pack = new SimStatsPacket(); | ||
499 | pack.Region = new SimStatsPacket.RegionBlock(); | ||
500 | pack.Region.RegionX = stats.RegionX; | ||
501 | pack.Region.RegionY = stats.RegionY; | ||
502 | pack.Region.RegionFlags = stats.RegionFlags; | ||
503 | pack.Region.ObjectCapacity = stats.ObjectCapacity; | ||
504 | //pack.Region = //stats.RegionBlock; | ||
505 | pack.Stat = stats.StatsBlock; | ||
506 | pack.Header.Reliable = false; | ||
507 | |||
508 | // note that we are inside the reporter lock when called | ||
509 | DateTime now = DateTime.Now; | ||
510 | |||
511 | // hide some time information into the packet | ||
512 | pack.Header.Sequence = (uint)now.Ticks; | ||
513 | |||
514 | lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here | ||
515 | { | ||
516 | try | ||
517 | { | ||
518 | if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod) | ||
519 | { | ||
520 | // First log file or time has expired, start writing to a new log file | ||
521 | if (m_statLog != null && m_statLog.Log != null) | ||
522 | { | ||
523 | m_statLog.Log.Close(); | ||
524 | } | ||
525 | m_statLog = new StatLogger(); | ||
526 | m_statLog.StartTime = now; | ||
527 | m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") | ||
528 | + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss")); | ||
529 | m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write)); | ||
530 | } | ||
531 | |||
532 | // Write the serialized data to disk | ||
533 | if (m_statLog != null && m_statLog.Log != null) | ||
534 | m_statLog.Log.Write(pack.ToBytes()); | ||
535 | } | ||
536 | catch (Exception ex) | ||
537 | { | ||
538 | m_log.Error("statistics gathering failed: " + ex.Message, ex); | ||
539 | if (m_statLog != null && m_statLog.Log != null) | ||
540 | { | ||
541 | m_statLog.Log.Close(); | ||
542 | } | ||
543 | m_statLog = null; | ||
544 | } | ||
545 | } | ||
546 | return; | ||
547 | } | ||
548 | |||
549 | #endregion | ||
550 | |||
551 | #region Constructors | 484 | #region Constructors |
552 | 485 | ||
553 | public Scene(RegionInfo regInfo, AgentCircuitManager authen, | 486 | public Scene(RegionInfo regInfo, AgentCircuitManager authen, |
@@ -752,38 +685,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
752 | } | 685 | } |
753 | 686 | ||
754 | m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); | 687 | m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); |
755 | |||
756 | #region BinaryStats | ||
757 | |||
758 | try | ||
759 | { | ||
760 | IConfig statConfig = m_config.Configs["Statistics.Binary"]; | ||
761 | if (statConfig.Contains("enabled") && statConfig.GetBoolean("enabled")) | ||
762 | { | ||
763 | if (statConfig.Contains("collect_region_stats")) | ||
764 | { | ||
765 | if (statConfig.GetBoolean("collect_region_stats")) | ||
766 | { | ||
767 | // if enabled, add us to the event. If not enabled, I won't get called | ||
768 | StatsReporter.OnSendStatsResult += LogSimStats; | ||
769 | } | ||
770 | } | ||
771 | if (statConfig.Contains("region_stats_period_seconds")) | ||
772 | { | ||
773 | m_statLogPeriod = TimeSpan.FromSeconds(statConfig.GetInt("region_stats_period_seconds")); | ||
774 | } | ||
775 | if (statConfig.Contains("stats_dir")) | ||
776 | { | ||
777 | m_statsDir = statConfig.GetString("stats_dir"); | ||
778 | } | ||
779 | } | ||
780 | } | ||
781 | catch | ||
782 | { | ||
783 | // if it doesn't work, we don't collect anything | ||
784 | } | ||
785 | |||
786 | #endregion BinaryStats | ||
787 | } | 688 | } |
788 | catch | 689 | catch |
789 | { | 690 | { |
@@ -2652,7 +2553,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2652 | if (!VerifyClient(aCircuit, ep, out vialogin)) | 2553 | if (!VerifyClient(aCircuit, ep, out vialogin)) |
2653 | { | 2554 | { |
2654 | // uh-oh, this is fishy | 2555 | // uh-oh, this is fishy |
2655 | m_log.WarnFormat("[Scene]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.", | 2556 | m_log.WarnFormat("[SCENE]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.", |
2656 | client.AgentId, client.SessionId, ep.ToString()); | 2557 | client.AgentId, client.SessionId, ep.ToString()); |
2657 | try | 2558 | try |
2658 | { | 2559 | { |
@@ -2660,13 +2561,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
2660 | } | 2561 | } |
2661 | catch (Exception e) | 2562 | catch (Exception e) |
2662 | { | 2563 | { |
2663 | m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace); | 2564 | m_log.DebugFormat("[SCENE]: Exception while closing aborted client: {0}", e.StackTrace); |
2664 | } | 2565 | } |
2665 | return; | 2566 | return; |
2666 | } | 2567 | } |
2667 | } | 2568 | } |
2668 | 2569 | ||
2669 | m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); | 2570 | m_log.Debug("[SCENE]: Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); |
2670 | 2571 | ||
2671 | ScenePresence sp = CreateAndAddScenePresence(client); | 2572 | ScenePresence sp = CreateAndAddScenePresence(client); |
2672 | if (aCircuit != null) | 2573 | if (aCircuit != null) |
@@ -2695,7 +2596,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2695 | // Do the verification here | 2596 | // Do the verification here |
2696 | if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0) | 2597 | if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0) |
2697 | { | 2598 | { |
2698 | m_log.DebugFormat("[Scene]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); | 2599 | m_log.DebugFormat("[SCENE]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); |
2699 | vialogin = true; | 2600 | vialogin = true; |
2700 | IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>(); | 2601 | IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>(); |
2701 | if (userVerification != null && ep != null) | 2602 | if (userVerification != null && ep != null) |
@@ -2705,11 +2606,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
2705 | if (!userVerification.VerifyClient(aCircuit, /*ep.Address.ToString() */ addr.ToString())) | 2606 | if (!userVerification.VerifyClient(aCircuit, /*ep.Address.ToString() */ addr.ToString())) |
2706 | { | 2607 | { |
2707 | // uh-oh, this is fishy | 2608 | // uh-oh, this is fishy |
2708 | m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} in {2} returned false", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); | 2609 | m_log.DebugFormat("[SCENE]: User Client Verification for {0} {1} in {2} returned false", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); |
2709 | return false; | 2610 | return false; |
2710 | } | 2611 | } |
2711 | else | 2612 | else |
2712 | m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} in {2} returned true", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); | 2613 | m_log.DebugFormat("[SCENE]: User Client Verification for {0} {1} in {2} returned true", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); |
2713 | } | 2614 | } |
2714 | } | 2615 | } |
2715 | 2616 | ||
@@ -2740,7 +2641,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2740 | } | 2641 | } |
2741 | catch (Exception e) | 2642 | catch (Exception e) |
2742 | { | 2643 | { |
2743 | m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace); | 2644 | m_log.DebugFormat("[SCENE]: Exception while closing aborted client: {0}", e.StackTrace); |
2744 | } | 2645 | } |
2745 | } | 2646 | } |
2746 | else | 2647 | else |