use of org.eclipse.jetty.server.AsyncContextState in project metrics by dropwizard.
the class InstrumentedHandler method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
final String prefix = this.prefix == null ? name(getHandler().getClass(), name) : name(this.prefix, name);
this.requests = metricRegistry.timer(name(prefix, "requests"));
this.dispatches = metricRegistry.timer(name(prefix, "dispatches"));
this.activeRequests = metricRegistry.counter(name(prefix, "active-requests"));
this.activeDispatches = metricRegistry.counter(name(prefix, "active-dispatches"));
this.activeSuspended = metricRegistry.counter(name(prefix, "active-suspended"));
this.asyncDispatches = metricRegistry.meter(name(prefix, "async-dispatches"));
this.asyncTimeouts = metricRegistry.meter(name(prefix, "async-timeouts"));
this.responses = new Meter[] { // 1xx
metricRegistry.meter(name(prefix, "1xx-responses")), // 2xx
metricRegistry.meter(name(prefix, "2xx-responses")), // 3xx
metricRegistry.meter(name(prefix, "3xx-responses")), // 4xx
metricRegistry.meter(name(prefix, "4xx-responses")), // 5xx
metricRegistry.meter(name(prefix, "5xx-responses")) };
this.getRequests = metricRegistry.timer(name(prefix, "get-requests"));
this.postRequests = metricRegistry.timer(name(prefix, "post-requests"));
this.headRequests = metricRegistry.timer(name(prefix, "head-requests"));
this.putRequests = metricRegistry.timer(name(prefix, "put-requests"));
this.deleteRequests = metricRegistry.timer(name(prefix, "delete-requests"));
this.optionsRequests = metricRegistry.timer(name(prefix, "options-requests"));
this.traceRequests = metricRegistry.timer(name(prefix, "trace-requests"));
this.connectRequests = metricRegistry.timer(name(prefix, "connect-requests"));
this.moveRequests = metricRegistry.timer(name(prefix, "move-requests"));
this.otherRequests = metricRegistry.timer(name(prefix, "other-requests"));
metricRegistry.register(name(prefix, "percent-4xx-1m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getOneMinuteRate(), requests.getOneMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-4xx-5m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getFiveMinuteRate(), requests.getFiveMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-4xx-15m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getFifteenMinuteRate(), requests.getFifteenMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-1m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getOneMinuteRate(), requests.getOneMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-5m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getFiveMinuteRate(), requests.getFiveMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-15m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getFifteenMinuteRate(), requests.getFifteenMinuteRate());
}
});
this.listener = new AsyncListener() {
private long startTime;
@Override
public void onTimeout(AsyncEvent event) throws IOException {
asyncTimeouts.mark();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
startTime = System.currentTimeMillis();
event.getAsyncContext().addListener(this);
}
@Override
public void onError(AsyncEvent event) throws IOException {
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
final AsyncContextState state = (AsyncContextState) event.getAsyncContext();
final HttpServletRequest request = (HttpServletRequest) state.getRequest();
final HttpServletResponse response = (HttpServletResponse) state.getResponse();
updateResponses(request, response, startTime);
if (state.getHttpChannelState().getState() != HttpChannelState.State.DISPATCHED) {
activeSuspended.dec();
}
}
};
}
use of org.eclipse.jetty.server.AsyncContextState in project chassis by Kixeye.
the class InstrumentedHandler method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
final String prefix = name(getHandler().getClass(), name);
this.requests = timer(name(prefix, "requests"));
this.dispatches = timer(name(prefix, "dispatches"));
this.activeRequests = metricRegistry.counter(name(prefix, "active-requests"));
this.activeDispatches = metricRegistry.counter(name(prefix, "active-dispatches"));
this.activeSuspended = metricRegistry.counter(name(prefix, "active-suspended"));
this.asyncDispatches = metricRegistry.meter(name(prefix, "async-dispatches"));
this.asyncTimeouts = metricRegistry.meter(name(prefix, "async-timeouts"));
this.responses = new Meter[] { // 1xx
metricRegistry.meter(name(prefix, "1xx-responses")), // 2xx
metricRegistry.meter(name(prefix, "2xx-responses")), // 3xx
metricRegistry.meter(name(prefix, "3xx-responses")), // 4xx
metricRegistry.meter(name(prefix, "4xx-responses")), // 5xx
metricRegistry.meter(name(prefix, "5xx-responses")) };
this.getRequests = timer(name(prefix, "get-requests"));
this.postRequests = timer(name(prefix, "post-requests"));
this.headRequests = timer(name(prefix, "head-requests"));
this.putRequests = timer(name(prefix, "put-requests"));
this.deleteRequests = timer(name(prefix, "delete-requests"));
this.optionsRequests = timer(name(prefix, "options-requests"));
this.traceRequests = timer(name(prefix, "trace-requests"));
this.connectRequests = timer(name(prefix, "connect-requests"));
this.moveRequests = timer(name(prefix, "move-requests"));
this.otherRequests = timer(name(prefix, "other-requests"));
this.listener = new AsyncListener() {
@Override
public void onTimeout(AsyncEvent event) throws IOException {
asyncTimeouts.mark();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
event.getAsyncContext().addListener(this);
}
@Override
public void onError(AsyncEvent event) throws IOException {
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
final AsyncContextState state = (AsyncContextState) event.getAsyncContext();
final Request request = (Request) state.getRequest();
updateResponses(request);
if (!(state.getHttpChannelState().getState() == State.DISPATCHED)) {
activeSuspended.dec();
}
}
};
}
Aggregations