mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-06 05:49:50 +00:00
Merged branch 'jetty-9.4.x' into 'master'.
Removed deprecated ConnectorStatistics class and its usages.
This commit is contained in:
commit
eb78d5e2c3
@ -72,10 +72,10 @@ This example comes from within `jetty-http.xml`.
|
||||
<Set name="host"><Property name="jetty.host" /></Set>
|
||||
<Set name="port"><Property name="jetty.http.port" default="8080" /></Set>
|
||||
<Set name="idleTimeout">30000</Set>
|
||||
<!-- Enable Connector Statistics -->
|
||||
<!-- Enable Connection Statistics -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="ConnectorStatistics" class="org.eclipse.jetty.server.ConnectorStatistics"/>
|
||||
<New id="ConnectionStatistics" class="org.eclipse.jetty.io.ConnectionStatistics"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
</New>
|
||||
|
@ -27,13 +27,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.io.ConnectionStatistics;
|
||||
import org.eclipse.jetty.security.ConstraintMapping;
|
||||
import org.eclipse.jetty.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.ConnectorStatistics;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.NCSARequestLog;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
@ -395,15 +395,15 @@ public class Runner
|
||||
connector.setHost(host);
|
||||
_server.addConnector(connector);
|
||||
if (_enableStats)
|
||||
connector.addBean(new ConnectorStatistics());
|
||||
connector.addBean(new ConnectionStatistics());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_enableStats)
|
||||
{
|
||||
for (Connector connector : connectors)
|
||||
for (Connector connector : connectors)
|
||||
{
|
||||
((AbstractConnector) connector).addBean(new ConnectorStatistics());
|
||||
((AbstractConnector) connector).addBean(new ConnectionStatistics());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,311 +0,0 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Container;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.statistic.CounterStatistic;
|
||||
import org.eclipse.jetty.util.statistic.SampleStatistic;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** A Connector.Listener that gathers Connector and Connections Statistics.
|
||||
* Adding an instance of this class as with {@link AbstractConnector#addBean(Object)}
|
||||
* will register the listener with all connections accepted by that connector.
|
||||
*
|
||||
* @deprecated use {@link ServerConnectionStatistics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@ManagedObject("Connector Statistics")
|
||||
public class ConnectorStatistics extends AbstractLifeCycle implements Dumpable, Connection.Listener
|
||||
{
|
||||
private final static Sample ZERO=new Sample();
|
||||
private final AtomicLong _startMillis = new AtomicLong(-1L);
|
||||
private final CounterStatistic _connectionStats = new CounterStatistic();
|
||||
private final SampleStatistic _messagesIn = new SampleStatistic();
|
||||
private final SampleStatistic _messagesOut = new SampleStatistic();
|
||||
private final SampleStatistic _connectionDurationStats = new SampleStatistic();
|
||||
private final ConcurrentMap<Connection, Sample> _samples = new ConcurrentHashMap<>();
|
||||
private final LongAdder _closedIn = new LongAdder();
|
||||
private final LongAdder _closedOut = new LongAdder();
|
||||
private AtomicLong _nanoStamp=new AtomicLong();
|
||||
private volatile int _messagesInPerSecond;
|
||||
private volatile int _messagesOutPerSecond;
|
||||
|
||||
@Override
|
||||
public void onOpened(Connection connection)
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
_connectionStats.increment();
|
||||
_samples.put(connection,ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(Connection connection)
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
long msgsIn=connection.getMessagesIn();
|
||||
long msgsOut=connection.getMessagesOut();
|
||||
_messagesIn.set(msgsIn);
|
||||
_messagesOut.set(msgsOut);
|
||||
_connectionStats.decrement();
|
||||
_connectionDurationStats.set(System.currentTimeMillis()-connection.getCreatedTimeStamp());
|
||||
|
||||
Sample sample=_samples.remove(connection);
|
||||
if (sample!=null)
|
||||
{
|
||||
_closedIn.add(msgsIn-sample._messagesIn);
|
||||
_closedOut.add(msgsOut-sample._messagesOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ManagedAttribute("Total number of bytes received by this connector")
|
||||
public int getBytesIn()
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ManagedAttribute("Total number of bytes sent by this connector")
|
||||
public int getBytesOut()
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ManagedAttribute("Total number of connections seen by this connector")
|
||||
public int getConnections()
|
||||
{
|
||||
return (int)_connectionStats.getTotal();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connection duration maximum in ms")
|
||||
public long getConnectionDurationMax()
|
||||
{
|
||||
return _connectionDurationStats.getMax();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connection duration mean in ms")
|
||||
public double getConnectionDurationMean()
|
||||
{
|
||||
return _connectionDurationStats.getMean();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connection duration standard deviation")
|
||||
public double getConnectionDurationStdDev()
|
||||
{
|
||||
return _connectionDurationStats.getStdDev();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In for all connections")
|
||||
public int getMessagesIn()
|
||||
{
|
||||
return (int)_messagesIn.getTotal();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection maximum")
|
||||
public int getMessagesInPerConnectionMax()
|
||||
{
|
||||
return (int)_messagesIn.getMax();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection mean")
|
||||
public double getMessagesInPerConnectionMean()
|
||||
{
|
||||
return _messagesIn.getMean();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection standard deviation")
|
||||
public double getMessagesInPerConnectionStdDev()
|
||||
{
|
||||
return _messagesIn.getStdDev();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connections open")
|
||||
public int getConnectionsOpen()
|
||||
{
|
||||
return (int)_connectionStats.getCurrent();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connections open maximum")
|
||||
public int getConnectionsOpenMax()
|
||||
{
|
||||
return (int)_connectionStats.getMax();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages Out for all connections")
|
||||
public int getMessagesOut()
|
||||
{
|
||||
return (int)_messagesIn.getTotal();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection maximum")
|
||||
public int getMessagesOutPerConnectionMax()
|
||||
{
|
||||
return (int)_messagesIn.getMax();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection mean")
|
||||
public double getMessagesOutPerConnectionMean()
|
||||
{
|
||||
return _messagesIn.getMean();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages In per connection standard deviation")
|
||||
public double getMessagesOutPerConnectionStdDev()
|
||||
{
|
||||
return _messagesIn.getStdDev();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Connection statistics started ms since epoch")
|
||||
public long getStartedMillis()
|
||||
{
|
||||
long start = _startMillis.get();
|
||||
return start < 0 ? 0 : System.currentTimeMillis() - start;
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages in per second calculated over period since last called")
|
||||
public int getMessagesInPerSecond()
|
||||
{
|
||||
update();
|
||||
return _messagesInPerSecond;
|
||||
}
|
||||
|
||||
@ManagedAttribute("Messages out per second calculated over period since last called")
|
||||
public int getMessagesOutPerSecond()
|
||||
{
|
||||
update();
|
||||
return _messagesOutPerSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStart()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStop()
|
||||
{
|
||||
_samples.clear();
|
||||
}
|
||||
|
||||
@ManagedOperation("Reset the statistics")
|
||||
public void reset()
|
||||
{
|
||||
_startMillis.set(System.currentTimeMillis());
|
||||
_messagesIn.reset();
|
||||
_messagesOut.reset();
|
||||
_connectionStats.reset();
|
||||
_connectionDurationStats.reset();
|
||||
_samples.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedOperation("dump thread state")
|
||||
public String dump()
|
||||
{
|
||||
return ContainerLifeCycle.dump(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
ContainerLifeCycle.dumpObject(out,this);
|
||||
ContainerLifeCycle.dump(out,indent,Arrays.asList(new String[]{"connections="+_connectionStats,"duration="+_connectionDurationStats,"in="+_messagesIn,"out="+_messagesOut}));
|
||||
}
|
||||
|
||||
public static void addToAllConnectors(Server server)
|
||||
{
|
||||
for (Connector connector : server.getConnectors())
|
||||
{
|
||||
if (connector instanceof Container)
|
||||
((Container)connector).addBean(new ConnectorStatistics());
|
||||
}
|
||||
}
|
||||
|
||||
private static final long SECOND_NANOS=TimeUnit.SECONDS.toNanos(1);
|
||||
private synchronized void update()
|
||||
{
|
||||
long now=System.nanoTime();
|
||||
long then=_nanoStamp.get();
|
||||
long duration=now-then;
|
||||
|
||||
if (duration>SECOND_NANOS/2)
|
||||
{
|
||||
if (_nanoStamp.compareAndSet(then,now))
|
||||
{
|
||||
long msgsIn=_closedIn.sumThenReset();
|
||||
long msgsOut=_closedOut.sumThenReset();
|
||||
|
||||
for (Map.Entry<Connection, Sample> entry : _samples.entrySet())
|
||||
{
|
||||
Connection connection=entry.getKey();
|
||||
Sample sample = entry.getValue();
|
||||
Sample next = new Sample(connection);
|
||||
if (_samples.replace(connection,sample,next))
|
||||
{
|
||||
msgsIn+=next._messagesIn-sample._messagesIn;
|
||||
msgsOut+=next._messagesOut-sample._messagesOut;
|
||||
}
|
||||
}
|
||||
|
||||
_messagesInPerSecond=(int)(msgsIn*SECOND_NANOS/duration);
|
||||
_messagesOutPerSecond=(int)(msgsOut*SECOND_NANOS/duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Sample
|
||||
{
|
||||
Sample()
|
||||
{
|
||||
_messagesIn=0;
|
||||
_messagesOut=0;
|
||||
}
|
||||
|
||||
Sample(Connection connection)
|
||||
{
|
||||
_messagesIn=connection.getMessagesIn();
|
||||
_messagesOut=connection.getMessagesOut();
|
||||
}
|
||||
|
||||
final long _messagesIn;
|
||||
final long _messagesOut;
|
||||
}
|
||||
}
|
@ -1,266 +0,0 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore("Ignored while refactoring the connection events and statistics")
|
||||
public class ConnectorStatisticsTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ConnectorStatisticsTest.class);
|
||||
|
||||
private static Server _server;
|
||||
private static ConnectorStatistics _statistics;
|
||||
private static AbstractNetworkConnector _connector;
|
||||
private static CyclicBarrier _connect;
|
||||
private static CountDownLatch _closed;
|
||||
|
||||
private Socket[] _socket;
|
||||
private PrintWriter[] _out;
|
||||
private BufferedReader[] _in;
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() throws Exception
|
||||
{
|
||||
_connect = new CyclicBarrier(2);
|
||||
|
||||
_server = new Server();
|
||||
_connector = new ServerConnector(_server);
|
||||
_statistics = new ConnectorStatistics();
|
||||
_connector.addBean(_statistics);
|
||||
_server.addConnector(_connector);
|
||||
|
||||
HandlerWrapper wrapper = new HandlerWrapper()
|
||||
{
|
||||
@Override
|
||||
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
_connect.await();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.debug(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
super.handle(path, request, httpRequest, httpResponse);
|
||||
}
|
||||
}
|
||||
};
|
||||
_server.setHandler(wrapper);
|
||||
|
||||
Handler handler = new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
try{Thread.sleep(1);} catch(Exception e){}
|
||||
baseRequest.setHandled(true);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.write("Server response\n");
|
||||
out.close();
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
};
|
||||
wrapper.setHandler(handler);
|
||||
|
||||
_server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() throws Exception
|
||||
{
|
||||
_server.stop();
|
||||
_server.join();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
_statistics.reset();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tini() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleRequest() throws Exception
|
||||
{
|
||||
doInit(1);
|
||||
|
||||
sendRequest(1, 1);
|
||||
|
||||
doClose(1);
|
||||
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(0, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnectionsOpenMax());
|
||||
assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax());
|
||||
|
||||
assertTrue(_statistics.getConnectionDurationMean() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMax() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMean() <= _statistics.getConnectionDurationMax());
|
||||
|
||||
assertEquals(1, _statistics.getMessagesIn());
|
||||
assertEquals(1.0, _statistics.getMessagesInPerConnectionMean(), 0.01);
|
||||
assertEquals(1, _statistics.getMessagesInPerConnectionMax());
|
||||
assertTrue(_statistics.getMessagesInPerConnectionMean() <= _statistics.getMessagesInPerConnectionMax());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleRequests() throws Exception
|
||||
{
|
||||
doInit(1);
|
||||
|
||||
sendRequest(1, 1);
|
||||
|
||||
sendRequest(1, 1);
|
||||
|
||||
doClose(1);
|
||||
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(0, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnectionsOpenMax());
|
||||
assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax());
|
||||
|
||||
assertTrue(_statistics.getConnectionDurationMean() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMax() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMean() <= _statistics.getConnectionDurationMax());
|
||||
|
||||
assertEquals(2, _statistics.getMessagesIn());
|
||||
assertEquals(2.0, _statistics.getMessagesInPerConnectionMean(), 0.01);
|
||||
assertEquals(2, _statistics.getMessagesInPerConnectionMax());
|
||||
assertTrue(_statistics.getMessagesInPerConnectionMean() <= _statistics.getMessagesInPerConnectionMax());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConnections() throws Exception
|
||||
{
|
||||
doInit(3);
|
||||
|
||||
sendRequest(1, 1); // request 1 connection 1
|
||||
|
||||
sendRequest(2, 2); // request 1 connection 2
|
||||
|
||||
sendRequest(3, 3); // request 1 connection 3
|
||||
|
||||
sendRequest(2, 3); // request 2 connection 2
|
||||
|
||||
sendRequest(3, 3); // request 2 connection 3
|
||||
|
||||
sendRequest(3, 3); // request 3 connection 3
|
||||
|
||||
doClose(3);
|
||||
|
||||
assertEquals(3, _statistics.getConnections());
|
||||
assertEquals(0, _statistics.getConnectionsOpen());
|
||||
assertEquals(3, _statistics.getConnectionsOpenMax());
|
||||
assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax());
|
||||
|
||||
assertTrue(_statistics.getConnectionDurationMean() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMax() > 0);
|
||||
assertTrue(_statistics.getConnectionDurationMean() <= _statistics.getConnectionDurationMax());
|
||||
|
||||
assertEquals(6, _statistics.getMessagesIn());
|
||||
assertEquals(2.0, _statistics.getMessagesInPerConnectionMean(), 0.01);
|
||||
assertEquals(3, _statistics.getMessagesInPerConnectionMax());
|
||||
assertTrue(_statistics.getMessagesInPerConnectionMean() <= _statistics.getMessagesInPerConnectionMax());
|
||||
}
|
||||
|
||||
protected void doInit(int count)
|
||||
{
|
||||
_socket = new Socket[count];
|
||||
_out = new PrintWriter[count];
|
||||
_in = new BufferedReader[count];
|
||||
|
||||
_closed = new CountDownLatch(count);
|
||||
}
|
||||
|
||||
private void doClose(int count) throws Exception
|
||||
{
|
||||
for (int idx=0; idx < count; idx++)
|
||||
{
|
||||
if (_socket[idx] != null)
|
||||
{
|
||||
_socket[idx].close();
|
||||
}
|
||||
}
|
||||
|
||||
_closed.await();
|
||||
}
|
||||
|
||||
private void sendRequest(int id, int count) throws Exception
|
||||
{
|
||||
int idx = id - 1;
|
||||
|
||||
if (idx < 0)
|
||||
throw new IllegalArgumentException("Connection ID <= 0");
|
||||
|
||||
_socket[idx] = _socket[idx] == null ? new Socket("localhost", _connector.getLocalPort()) : _socket[idx];
|
||||
_out[idx] = _out[idx] == null ? new PrintWriter(_socket[idx].getOutputStream(), true) : _out[idx];
|
||||
_in[idx] = _in[idx] == null ? new BufferedReader(new InputStreamReader(_socket[idx].getInputStream())) : _in[idx];
|
||||
|
||||
_connect.reset();
|
||||
|
||||
_out[idx].write("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
|
||||
_out[idx].flush();
|
||||
|
||||
_connect.await();
|
||||
|
||||
assertEquals(count, _statistics.getConnectionsOpen());
|
||||
|
||||
String line=_in[idx].readLine();
|
||||
while(line!=null)
|
||||
{
|
||||
if ("Server response".equals(line))
|
||||
break;
|
||||
line=_in[idx].readLine();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,12 +18,6 @@
|
||||
|
||||
package org.eclipse.jetty.server.handler;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
@ -37,7 +31,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.ConnectorStatistics;
|
||||
import org.eclipse.jetty.io.ConnectionStatistics;
|
||||
import org.eclipse.jetty.server.LocalConnector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
@ -45,10 +39,16 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StatisticsHandlerTest
|
||||
{
|
||||
private Server _server;
|
||||
private ConnectorStatistics _statistics;
|
||||
private ConnectionStatistics _statistics;
|
||||
private LocalConnector _connector;
|
||||
private LatchHandler _latchHandler;
|
||||
private StatisticsHandler _statsHandler;
|
||||
@ -59,7 +59,7 @@ public class StatisticsHandlerTest
|
||||
_server = new Server();
|
||||
|
||||
_connector = new LocalConnector(_server);
|
||||
_statistics = new ConnectorStatistics();
|
||||
_statistics = new ConnectionStatistics();
|
||||
_connector.addBean(_statistics);
|
||||
_server.addConnector(_connector);
|
||||
|
||||
@ -110,7 +110,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
@ -145,7 +145,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(2, _statistics.getConnectionsOpen());
|
||||
assertEquals(2, _statistics.getConnections());
|
||||
|
||||
assertEquals(2, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
@ -208,7 +208,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(2, _statistics.getConnectionsOpen());
|
||||
assertEquals(2, _statistics.getConnections());
|
||||
|
||||
assertEquals(2, _statsHandler.getRequests());
|
||||
assertEquals(2, _statsHandler.getRequestsActive());
|
||||
@ -282,7 +282,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
assertEquals(1, _statsHandler.getDispatched());
|
||||
@ -336,7 +336,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await(); // entered app handler
|
||||
|
||||
assertEquals(1, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
assertEquals(2, _statsHandler.getDispatched());
|
||||
@ -416,7 +416,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
assertEquals(1, _statsHandler.getDispatched());
|
||||
@ -532,7 +532,7 @@ public class StatisticsHandlerTest
|
||||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _statistics.getConnectionsOpen());
|
||||
assertEquals(1, _statistics.getConnections());
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
assertEquals(1, _statsHandler.getDispatched());
|
||||
|
@ -31,21 +31,17 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.io.ConnectionStatistics;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.ConnectorStatistics;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.util.component.Container;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* StatisticsServlet
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class StatisticsServlet extends HttpServlet
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(StatisticsServlet.class);
|
||||
@ -55,11 +51,6 @@ public class StatisticsServlet extends HttpServlet
|
||||
private MemoryMXBean _memoryBean;
|
||||
private Connector[] _connectors;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see javax.servlet.GenericServlet#init()
|
||||
*/
|
||||
public void init() throws ServletException
|
||||
{
|
||||
ServletContext context = getServletContext();
|
||||
@ -87,21 +78,11 @@ public class StatisticsServlet extends HttpServlet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void doPost(HttpServletRequest sreq, HttpServletResponse sres) throws ServletException, IOException
|
||||
{
|
||||
doGet(sreq, sres);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
if (_statsHandler == null)
|
||||
@ -131,7 +112,6 @@ public class StatisticsServlet extends HttpServlet
|
||||
{
|
||||
sendTextResponse(resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isLoopbackAddress(String address)
|
||||
@ -199,24 +179,26 @@ public class StatisticsServlet extends HttpServlet
|
||||
sb.append(" <protocol>").append(protocol).append("</protocol>\n");
|
||||
sb.append(" </protocols>\n");
|
||||
|
||||
ConnectorStatistics connectorStats = null;
|
||||
|
||||
ConnectionStatistics connectionStats = null;
|
||||
if (connector instanceof AbstractConnector)
|
||||
connectorStats = ((AbstractConnector)connector).getBean(ConnectorStatistics.class);
|
||||
if (connectorStats == null)
|
||||
sb.append(" <statsOn>false</statsOn>\n");
|
||||
else
|
||||
connectionStats = ((AbstractConnector)connector).getBean(ConnectionStatistics.class);
|
||||
if (connectionStats != null)
|
||||
{
|
||||
sb.append(" <statsOn>true</statsOn>\n");
|
||||
sb.append(" <connections>").append(connectorStats.getConnections()).append("</connections>\n");
|
||||
sb.append(" <connectionsOpen>").append(connectorStats.getConnectionsOpen()).append("</connectionsOpen>\n");
|
||||
sb.append(" <connectionsOpenMax>").append(connectorStats.getConnectionsOpenMax()).append("</connectionsOpenMax>\n");
|
||||
sb.append(" <connectionsDurationMean>").append(connectorStats.getConnectionDurationMean()).append("</connectionsDurationMean>\n");
|
||||
sb.append(" <connectionsDurationMax>").append(connectorStats.getConnectionDurationMax()).append("</connectionsDurationMax>\n");
|
||||
sb.append(" <connectionsDurationStdDev>").append(connectorStats.getConnectionDurationStdDev()).append("</connectionsDurationStdDev>\n");
|
||||
sb.append(" <messagesIn>").append(connectorStats.getMessagesIn()).append("</messagesIn>\n");
|
||||
sb.append(" <messagesOut>").append(connectorStats.getMessagesIn()).append("</messagesOut>\n");
|
||||
sb.append(" <elapsedMs>").append(connectorStats.getStartedMillis()).append("</elapsedMs>\n");
|
||||
sb.append(" <connections>").append(connectionStats.getConnectionsTotal()).append("</connections>\n");
|
||||
sb.append(" <connectionsOpen>").append(connectionStats.getConnections()).append("</connectionsOpen>\n");
|
||||
sb.append(" <connectionsOpenMax>").append(connectionStats.getConnectionsMax()).append("</connectionsOpenMax>\n");
|
||||
sb.append(" <connectionsDurationMean>").append(connectionStats.getConnectionDurationMean()).append("</connectionsDurationMean>\n");
|
||||
sb.append(" <connectionsDurationMax>").append(connectionStats.getConnectionDurationMax()).append("</connectionsDurationMax>\n");
|
||||
sb.append(" <connectionsDurationStdDev>").append(connectionStats.getConnectionDurationStdDev()).append("</connectionsDurationStdDev>\n");
|
||||
sb.append(" <bytesIn>").append(connectionStats.getReceivedBytes()).append("</bytesIn>\n");
|
||||
sb.append(" <bytesOut>").append(connectionStats.getSentBytes()).append("</connectorStats>\n");
|
||||
sb.append(" <messagesIn>").append(connectionStats.getReceivedMessages()).append("</messagesIn>\n");
|
||||
sb.append(" <messagesOut>").append(connectionStats.getSentMessages()).append("</messagesOut>\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(" <statsOn>false</statsOn>\n");
|
||||
}
|
||||
sb.append(" </connector>\n");
|
||||
}
|
||||
@ -234,12 +216,6 @@ public class StatisticsServlet extends HttpServlet
|
||||
pout.write(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
private void sendTextResponse(HttpServletResponse response) throws IOException
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -254,28 +230,26 @@ public class StatisticsServlet extends HttpServlet
|
||||
sb.append(protocol).append(" ");
|
||||
sb.append(" <br />\n");
|
||||
|
||||
ConnectorStatistics connectorStats = null;
|
||||
|
||||
if (connector instanceof AbstractConnector)
|
||||
connectorStats = ((AbstractConnector)connector).getBean(ConnectorStatistics.class);
|
||||
|
||||
if (connectorStats != null)
|
||||
ConnectionStatistics connectionStats = null;
|
||||
if (connector instanceof Container)
|
||||
connectionStats = ((Container)connector).getBean(ConnectionStatistics.class);
|
||||
if (connectionStats != null)
|
||||
{
|
||||
sb.append("Statistics gathering started ").append(connectorStats.getStartedMillis()).append("ms ago").append("<br />\n");
|
||||
sb.append("Total connections: ").append(connectorStats.getConnections()).append("<br />\n");
|
||||
sb.append("Current connections open: ").append(connectorStats.getConnectionsOpen()).append("<br />\n");;
|
||||
sb.append("Max concurrent connections open: ").append(connectorStats.getConnectionsOpenMax()).append("<br />\n");
|
||||
sb.append("Mean connection duration: ").append(connectorStats.getConnectionDurationMean()).append("<br />\n");
|
||||
sb.append("Max connection duration: ").append(connectorStats.getConnectionDurationMax()).append("<br />\n");
|
||||
sb.append("Connection duration standard deviation: ").append(connectorStats.getConnectionDurationStdDev()).append("<br />\n");
|
||||
sb.append("Total messages in: ").append(connectorStats.getMessagesIn()).append("<br />\n");
|
||||
sb.append("Total messages out: ").append(connectorStats.getMessagesOut()).append("<br />\n");
|
||||
sb.append("Total connections: ").append(connectionStats.getConnectionsTotal()).append("<br />\n");
|
||||
sb.append("Current connections open: ").append(connectionStats.getConnections()).append("<br />\n");
|
||||
sb.append("Max concurrent connections open: ").append(connectionStats.getConnectionsMax()).append("<br />\n");
|
||||
sb.append("Mean connection duration: ").append(connectionStats.getConnectionDurationMean()).append("<br />\n");
|
||||
sb.append("Max connection duration: ").append(connectionStats.getConnectionDurationMax()).append("<br />\n");
|
||||
sb.append("Connection duration standard deviation: ").append(connectionStats.getConnectionDurationStdDev()).append("<br />\n");
|
||||
sb.append("Total bytes received: ").append(connectionStats.getReceivedBytes()).append("<br />\n");
|
||||
sb.append("Total bytes sent: ").append(connectionStats.getSentBytes()).append("<br />\n");
|
||||
sb.append("Total messages received: ").append(connectionStats.getReceivedMessages()).append("<br />\n");
|
||||
sb.append("Total messages sent: ").append(connectionStats.getSentMessages()).append("<br />\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append("Statistics gathering off.\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sb.append("<h2>Memory:</h2>\n");
|
||||
@ -285,6 +259,5 @@ public class StatisticsServlet extends HttpServlet
|
||||
response.setContentType("text/html");
|
||||
PrintWriter pout = response.getWriter();
|
||||
pout.write(sb.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user