使用嵌入式 Jetty 计算每秒请求数
Counting number of requests per second with embedded Jetty
我有一个嵌入式 Jetty 服务器,我想知道它当前服务的每秒请求数。
有没有办法从 Jetty 获取这个号码?甚至我可以定期查询并自行计算我的 RPS 的总请求数?
统计处理程序中存在您要查找的内容。
处理程序允许收集请求统计信息的级别
- 从
AbstractConnector
的子类收集有关连接和请求数的统计信息
- 收集请求统计数据的 StatisticsHandler
可以通过 SessionHandler 和 DefaultSessionCache 的子类收集会话统计信息
AbstractConnector、SessionHandler 和 DefaultSessionCache 统计信息默认关闭,必须为每个实例手动配置或通过 JMX 接口打开。
默认 Jetty 配置中不包含 StatisticsHandler,需要手动配置。
您可以在 Jetty 中使用以下配置开启收集功能 xml
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<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 Connection Statistics -->
<Call name="addBean">
<Arg>
<New id="ConnectionStatistics" class="org.eclipse.jetty.io.ConnectionStatistics"/>
</Arg>
</Call>
</New>
</Arg>
</Call>
我有一个嵌入式 Jetty 服务器,我想知道它当前服务的每秒请求数。
有没有办法从 Jetty 获取这个号码?甚至我可以定期查询并自行计算我的 RPS 的总请求数?
统计处理程序中存在您要查找的内容。
处理程序允许收集请求统计信息的级别
- 从
AbstractConnector
的子类收集有关连接和请求数的统计信息
- 收集请求统计数据的 StatisticsHandler
可以通过 SessionHandler 和 DefaultSessionCache 的子类收集会话统计信息
AbstractConnector、SessionHandler 和 DefaultSessionCache 统计信息默认关闭,必须为每个实例手动配置或通过 JMX 接口打开。
默认 Jetty 配置中不包含 StatisticsHandler,需要手动配置。
您可以在 Jetty 中使用以下配置开启收集功能 xml
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<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 Connection Statistics -->
<Call name="addBean">
<Arg>
<New id="ConnectionStatistics" class="org.eclipse.jetty.io.ConnectionStatistics"/>
</Arg>
</Call>
</New>
</Arg>
</Call>