mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
Add "show caps stats by user" and "show caps stats by cap" console commands to print various counts of capability invocation by user and by cap
This currently prints caps requests received and handled, so that overload of received compared to handled or deadlock can be detected. This involves making BaseStreamHandler and BaseOutputStream record the ints, which means inheritors should subclass ProcessRequest() instead of Handle() However, existing inheriting classes overriding Handle() will still work, albeit without stats recording. "show caps" becomes "show caps list" to disambiguate between show caps commands
This commit is contained in:
@@ -31,6 +31,10 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
public abstract class BaseRequestHandler
|
||||
{
|
||||
public int RequestsReceived { get; protected set; }
|
||||
|
||||
public int RequestsHandled { get; protected set; }
|
||||
|
||||
public virtual string ContentType
|
||||
{
|
||||
get { return "application/xml"; }
|
||||
|
||||
@@ -29,14 +29,35 @@ using System.IO;
|
||||
|
||||
namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Base streamed request handler.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Inheriting classes should override ProcessRequest() rather than Handle()
|
||||
/// </remarks>
|
||||
public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler
|
||||
{
|
||||
public abstract byte[] Handle(string path, Stream request,
|
||||
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse);
|
||||
|
||||
protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) {}
|
||||
|
||||
protected BaseStreamHandler(string httpMethod, string path, string name, string description)
|
||||
: base(httpMethod, path, name, description) {}
|
||||
|
||||
public virtual byte[] Handle(
|
||||
string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
RequestsReceived++;
|
||||
|
||||
byte[] result = ProcessRequest(path, request, httpRequest, httpResponse);
|
||||
|
||||
RequestsHandled++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual byte[] ProcessRequest(
|
||||
string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
m_method = binaryMethod;
|
||||
}
|
||||
|
||||
public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
byte[] data = ReadFully(request);
|
||||
string param = GetParam(path);
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
public interface IRequestHandler
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Name for this handler.
|
||||
/// </summary>
|
||||
@@ -59,6 +58,19 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
// Return path
|
||||
string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of requests received by this handler
|
||||
/// </summary>
|
||||
int RequestsReceived { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of requests handled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Should be equal to RequestsReceived unless requested are being handled slowly or there is deadlock.
|
||||
/// </remarks>
|
||||
int RequestsHandled { get; }
|
||||
}
|
||||
|
||||
public interface IStreamedRequestHandler : IRequestHandler
|
||||
@@ -69,7 +81,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
public interface IStreamHandler : IRequestHandler
|
||||
{
|
||||
// Handle request stream, return byte array
|
||||
void Handle(string path, Stream request, Stream response, IOSHttpRequest httpReqbuest, IOSHttpResponse httpResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
public delegate TResponse RestDeserialiseMethod<TRequest, TResponse>(TRequest request);
|
||||
|
||||
public class RestDeserialiseHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
||||
public class RestDeserialiseHandler<TRequest, TResponse> : BaseOutputStreamHandler, IStreamHandler
|
||||
where TRequest : new()
|
||||
{
|
||||
private RestDeserialiseMethod<TRequest, TResponse> m_method;
|
||||
@@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
m_method = method;
|
||||
}
|
||||
|
||||
public void Handle(string path, Stream request, Stream responseStream,
|
||||
protected override void ProcessRequest(string path, Stream request, Stream responseStream,
|
||||
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
TRequest deserial;
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
public delegate bool CheckIdentityMethod(string sid, string aid);
|
||||
|
||||
public class RestDeserialiseSecureHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
||||
public class RestDeserialiseSecureHandler<TRequest, TResponse> : BaseOutputStreamHandler, IStreamHandler
|
||||
where TRequest : new()
|
||||
{
|
||||
private static readonly ILog m_log
|
||||
@@ -201,7 +201,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
m_method = method;
|
||||
}
|
||||
|
||||
public void Handle(string path, Stream request, Stream responseStream,
|
||||
protected override void ProcessRequest(string path, Stream request, Stream responseStream,
|
||||
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
RestSessionObject<TRequest> deserial = default(RestSessionObject<TRequest>);
|
||||
@@ -237,7 +237,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
public delegate bool CheckTrustedSourceMethod(IPEndPoint peer);
|
||||
|
||||
public class RestDeserialiseTrustedHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
||||
public class RestDeserialiseTrustedHandler<TRequest, TResponse> : BaseOutputStreamHandler, IStreamHandler
|
||||
where TRequest : new()
|
||||
{
|
||||
private static readonly ILog m_log
|
||||
@@ -260,7 +260,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
m_method = method;
|
||||
}
|
||||
|
||||
public void Handle(string path, Stream request, Stream responseStream,
|
||||
protected override void ProcessRequest(string path, Stream request, Stream responseStream,
|
||||
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
TRequest deserial = default(TRequest);
|
||||
@@ -292,6 +292,5 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
serializer.Serialize(xmlWriter, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
m_restMethod = restMethod;
|
||||
}
|
||||
|
||||
public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
Encoding encoding = Encoding.UTF8;
|
||||
StreamReader streamReader = new StreamReader(request, encoding);
|
||||
|
||||
Reference in New Issue
Block a user