diff options
author | Justin Clarke Casey | 2008-01-23 19:09:50 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-01-23 19:09:50 +0000 |
commit | 257f2b5583b79d37bc61db961c7404346e39725e (patch) | |
tree | 6f835730aeca8faa97c0039cf54498b22caa5c19 /OpenSim/Grid/AssetServer | |
parent | * Library scripts can now be dragged into prims (diff) | |
download | opensim-SC-257f2b5583b79d37bc61db961c7404346e39725e.zip opensim-SC-257f2b5583b79d37bc61db961c7404346e39725e.tar.gz opensim-SC-257f2b5583b79d37bc61db961c7404346e39725e.tar.bz2 opensim-SC-257f2b5583b79d37bc61db961c7404346e39725e.tar.xz |
* Add very very very basic initial statistical information collection to asset server
* stats can be seen by typing stats on the asset server command line
* Currently collecting only raw requests for today and yesterday
* And I haven't yet tested the 24 hour rollover
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/AssetServer/AssetStatsReporter.cs | 82 | ||||
-rw-r--r-- | OpenSim/Grid/AssetServer/Main.cs | 18 | ||||
-rw-r--r-- | OpenSim/Grid/AssetServer/RestService.cs | 25 |
3 files changed, 112 insertions, 13 deletions
diff --git a/OpenSim/Grid/AssetServer/AssetStatsReporter.cs b/OpenSim/Grid/AssetServer/AssetStatsReporter.cs new file mode 100644 index 0000000..dac44df --- /dev/null +++ b/OpenSim/Grid/AssetServer/AssetStatsReporter.cs | |||
@@ -0,0 +1,82 @@ | |||
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 OpenSim 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 | |||
29 | using System.Text; | ||
30 | using System.Timers; | ||
31 | |||
32 | namespace OpenSim.Grid.AssetServer | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Collects and reports information on the requests made to the asset server | ||
36 | /// </summary> | ||
37 | public class AssetStatsReporter | ||
38 | { | ||
39 | private Timer ageStatsTimer = new Timer(24 * 60 * 60); | ||
40 | |||
41 | private long assetRequestsToday; | ||
42 | public long AssetRequestsToday { get { return assetRequestsToday; } } | ||
43 | |||
44 | private long assetRequestsYesterday; | ||
45 | public long AssetRequestsYesterday { get { return assetRequestsYesterday; } } | ||
46 | |||
47 | public AssetStatsReporter() | ||
48 | { | ||
49 | ageStatsTimer.Elapsed += new ElapsedEventHandler(OnAgeing); | ||
50 | ageStatsTimer.Enabled = true; | ||
51 | } | ||
52 | |||
53 | private void OnAgeing(object source, ElapsedEventArgs e) | ||
54 | { | ||
55 | assetRequestsYesterday = assetRequestsToday; | ||
56 | |||
57 | // There is a possibility that an asset request could occur between the execution of these | ||
58 | // two statements. But we're better off without the synchronization overhead. | ||
59 | assetRequestsToday = 0; | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Record that a request was made to the asset server | ||
64 | /// </summary> | ||
65 | public void AddRequest() | ||
66 | { | ||
67 | assetRequestsToday++; | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Report back collected statistical information. | ||
72 | /// </summary> | ||
73 | /// <returns></returns> | ||
74 | public string Report() | ||
75 | { | ||
76 | return string.Format( | ||
77 | @"Asset requests today : {0} | ||
78 | Asset requests yesterday : {1}", | ||
79 | AssetRequestsToday, AssetRequestsYesterday); | ||
80 | } | ||
81 | } | ||
82 | } | ||
diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index ed77e3e..4fc66f7 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs | |||
@@ -52,6 +52,8 @@ namespace OpenSim.Grid.AssetServer | |||
52 | protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); | 52 | protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); |
53 | 53 | ||
54 | private IAssetProvider m_assetProvider; | 54 | private IAssetProvider m_assetProvider; |
55 | |||
56 | private AssetStatsReporter stats; | ||
55 | 57 | ||
56 | [STAThread] | 58 | [STAThread] |
57 | public static void Main(string[] args) | 59 | public static void Main(string[] args) |
@@ -97,8 +99,11 @@ namespace OpenSim.Grid.AssetServer | |||
97 | 99 | ||
98 | m_console.Verbose("ASSET", "Starting HTTP process"); | 100 | m_console.Verbose("ASSET", "Starting HTTP process"); |
99 | BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); | 101 | BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); |
102 | |||
103 | // XXX Hardcoded - could be a plugin later on | ||
104 | stats = new AssetStatsReporter(); | ||
100 | 105 | ||
101 | httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider)); | 106 | httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider, stats)); |
102 | httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider)); | 107 | httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider)); |
103 | 108 | ||
104 | httpServer.Start(); | 109 | httpServer.Start(); |
@@ -172,7 +177,14 @@ namespace OpenSim.Grid.AssetServer | |||
172 | switch (cmd) | 177 | switch (cmd) |
173 | { | 178 | { |
174 | case "help": | 179 | case "help": |
175 | m_console.Notice("shutdown - shutdown this asset server (USE CAUTION!)"); | 180 | m_console.Notice( |
181 | @"shutdown - shutdown this asset server (USE CAUTION!) | ||
182 | stats - statistical information for this asset server"); | ||
183 | |||
184 | break; | ||
185 | |||
186 | case "stats": | ||
187 | MainLog.Instance.Notice("STATS", Environment.NewLine + stats.Report()); | ||
176 | break; | 188 | break; |
177 | 189 | ||
178 | case "shutdown": | 190 | case "shutdown": |
@@ -186,4 +198,4 @@ namespace OpenSim.Grid.AssetServer | |||
186 | { | 198 | { |
187 | } | 199 | } |
188 | } | 200 | } |
189 | } \ No newline at end of file | 201 | } |
diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs index ee44108..36dcdb0 100644 --- a/OpenSim/Grid/AssetServer/RestService.cs +++ b/OpenSim/Grid/AssetServer/RestService.cs | |||
@@ -42,7 +42,18 @@ namespace OpenSim.Grid.AssetServer | |||
42 | { | 42 | { |
43 | private OpenAsset_Main m_assetManager; | 43 | private OpenAsset_Main m_assetManager; |
44 | private IAssetProvider m_assetProvider; | 44 | private IAssetProvider m_assetProvider; |
45 | private AssetStatsReporter m_stats; | ||
45 | 46 | ||
47 | public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider, | ||
48 | AssetStatsReporter stats) | ||
49 | : base("GET", "/assets") | ||
50 | { | ||
51 | MainLog.Instance.Verbose("REST", "In Get Request"); | ||
52 | m_assetManager = assetManager; | ||
53 | m_assetProvider = assetProvider; | ||
54 | m_stats = stats; | ||
55 | } | ||
56 | |||
46 | public override byte[] Handle(string path, Stream request) | 57 | public override byte[] Handle(string path, Stream request) |
47 | { | 58 | { |
48 | MainLog.Instance.Verbose("REST", "In Handle"); | 59 | MainLog.Instance.Verbose("REST", "In Handle"); |
@@ -57,6 +68,8 @@ namespace OpenSim.Grid.AssetServer | |||
57 | LLUUID assetID = LLUUID.Parse(p[0]); | 68 | LLUUID assetID = LLUUID.Parse(p[0]); |
58 | 69 | ||
59 | MainLog.Instance.Verbose("REST", "GET:/asset fetch param={0} UUID={1}", param, assetID); | 70 | MainLog.Instance.Verbose("REST", "GET:/asset fetch param={0} UUID={1}", param, assetID); |
71 | m_stats.AddRequest(); | ||
72 | |||
60 | AssetBase asset = m_assetProvider.FetchAsset(assetID); | 73 | AssetBase asset = m_assetProvider.FetchAsset(assetID); |
61 | if (asset != null) | 74 | if (asset != null) |
62 | { | 75 | { |
@@ -70,7 +83,7 @@ namespace OpenSim.Grid.AssetServer | |||
70 | xw.Flush(); | 83 | xw.Flush(); |
71 | 84 | ||
72 | ms.Seek(0, SeekOrigin.Begin); | 85 | ms.Seek(0, SeekOrigin.Begin); |
73 | StreamReader sr = new StreamReader(ms); | 86 | //StreamReader sr = new StreamReader(ms); |
74 | 87 | ||
75 | result = ms.GetBuffer(); | 88 | result = ms.GetBuffer(); |
76 | MainLog.Instance.Verbose("REST", "Buffer: {0}", result); | 89 | MainLog.Instance.Verbose("REST", "Buffer: {0}", result); |
@@ -88,14 +101,6 @@ namespace OpenSim.Grid.AssetServer | |||
88 | } | 101 | } |
89 | return result; | 102 | return result; |
90 | } | 103 | } |
91 | |||
92 | public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider) | ||
93 | : base("GET", "/assets") | ||
94 | { | ||
95 | MainLog.Instance.Verbose("REST", "In Get Request"); | ||
96 | m_assetManager = assetManager; | ||
97 | m_assetProvider = assetProvider; | ||
98 | } | ||
99 | } | 104 | } |
100 | 105 | ||
101 | public class PostAssetStreamHandler : BaseStreamHandler | 106 | public class PostAssetStreamHandler : BaseStreamHandler |
@@ -129,4 +134,4 @@ namespace OpenSim.Grid.AssetServer | |||
129 | m_assetProvider = assetProvider; | 134 | m_assetProvider = assetProvider; |
130 | } | 135 | } |
131 | } | 136 | } |
132 | } \ No newline at end of file | 137 | } |