1717
1818package io .reactivex .netty .spectator .http ;
1919
20- import com .netflix .spectator .api .Counter ;
2120import com .netflix .spectator .api .Registry ;
2221import com .netflix .spectator .api .Spectator ;
2322import io .reactivex .netty .protocol .http .client .events .HttpClientEventsListener ;
2423import io .reactivex .netty .spectator .http .internal .ResponseCodesHolder ;
25- import io .reactivex .netty .spectator .internal .LatencyMetrics ;
24+ import io .reactivex .netty .spectator .internal .EventMetric ;
2625import io .reactivex .netty .spectator .tcp .TcpClientListener ;
2726
2827import java .util .concurrent .TimeUnit ;
29- import java .util .concurrent .atomic .AtomicInteger ;
30-
31- import static io .reactivex .netty .spectator .internal .SpectatorUtils .*;
3228
3329/**
3430 * HttpClientListener.
3531 */
3632public class HttpClientListener extends HttpClientEventsListener {
3733
38- private final AtomicInteger requestBacklog ;
39- private final AtomicInteger inflightRequests ;
40- private final Counter processedRequests ;
41- private final Counter requestWriteFailed ;
42- private final Counter failedResponses ;
34+ private final EventMetric requestWrite ;
35+ private final EventMetric requestProcessing ;
36+ private final EventMetric response ;
37+
4338 private final ResponseCodesHolder responseCodesHolder ;
44- private final LatencyMetrics requestWriteTimes ;
45- private final LatencyMetrics responseReadTimes ;
46- private final LatencyMetrics requestProcessingTimes ;
4739 private final TcpClientListener tcpDelegate ;
4840
4941 public HttpClientListener (Registry registry , String monitorId ) {
50- requestBacklog = newGauge (registry , "requestBacklog" , monitorId , new AtomicInteger ());
51- inflightRequests = newGauge (registry , "inflightRequests" , monitorId , new AtomicInteger ());
52- requestWriteTimes = new LatencyMetrics ("requestWriteTimes" , monitorId , registry );
53- responseReadTimes = new LatencyMetrics ("responseReadTimes" , monitorId , registry );
54- processedRequests = newCounter (registry , "processedRequests" , monitorId );
55- requestWriteFailed = newCounter (registry , "requestWriteFailed" , monitorId );
56- failedResponses = newCounter (registry , "failedResponses" , monitorId );
57- requestProcessingTimes = new LatencyMetrics ("requestProcessingTimes" , monitorId , registry );
42+ requestWrite = new EventMetric (registry , "request" , monitorId , "action" , "write" );
43+ requestProcessing = new EventMetric (registry , "request" , monitorId , "action" , "processing" );
44+ response = new EventMetric (registry , "response" , monitorId , "action" , "read" );
45+
5846 responseCodesHolder = new ResponseCodesHolder (registry , monitorId );
5947 tcpDelegate = new TcpClientListener (registry , monitorId );
6048 }
@@ -63,49 +51,9 @@ public HttpClientListener(String monitorId) {
6351 this (Spectator .globalRegistry (), monitorId );
6452 }
6553
66- public long getRequestBacklog () {
67- return requestBacklog .get ();
68- }
69-
70- public long getInflightRequests () {
71- return inflightRequests .get ();
72- }
73-
74- public long getProcessedRequests () {
75- return processedRequests .count ();
76- }
77-
78- public long getRequestWriteFailed () {
79- return requestWriteFailed .count ();
80- }
81-
82- public long getFailedResponses () {
83- return failedResponses .count ();
84- }
85-
86- public long getResponse1xx () {
87- return responseCodesHolder .getResponse1xx ();
88- }
89-
90- public long getResponse2xx () {
91- return responseCodesHolder .getResponse2xx ();
92- }
93-
94- public long getResponse3xx () {
95- return responseCodesHolder .getResponse3xx ();
96- }
97-
98- public long getResponse4xx () {
99- return responseCodesHolder .getResponse4xx ();
100- }
101-
102- public long getResponse5xx () {
103- return responseCodesHolder .getResponse5xx ();
104- }
105-
10654 @ Override
10755 public void onRequestProcessingComplete (long duration , TimeUnit timeUnit ) {
108- requestProcessingTimes . record (duration , timeUnit );
56+ requestProcessing . success (duration , timeUnit );
10957 }
11058
11159 @ Override
@@ -115,38 +63,32 @@ public void onResponseHeadersReceived(int responseCode, long duration, TimeUnit
11563
11664 @ Override
11765 public void onResponseReceiveComplete (long duration , TimeUnit timeUnit ) {
118- inflightRequests .decrementAndGet ();
119- processedRequests .increment ();
120- responseReadTimes .record (duration , timeUnit );
66+ response .success (duration , timeUnit );
12167 }
12268
12369 @ Override
12470 public void onRequestWriteStart () {
125- requestBacklog . decrementAndGet ();
71+ requestWrite . start ();
12672 }
12773
12874 @ Override
12975 public void onResponseFailed (Throwable throwable ) {
130- inflightRequests .decrementAndGet ();
131- processedRequests .increment ();
132- failedResponses .increment ();
76+ response .failure ();
13377 }
13478
13579 @ Override
13680 public void onRequestWriteComplete (long duration , TimeUnit timeUnit ) {
137- requestWriteTimes . record (duration , timeUnit );
81+ requestWrite . success (duration , timeUnit );
13882 }
13983
14084 @ Override
14185 public void onRequestWriteFailed (long duration , TimeUnit timeUnit , Throwable throwable ) {
142- inflightRequests .decrementAndGet ();
143- requestWriteFailed .increment ();
86+ requestWrite .failure (duration , timeUnit );
14487 }
14588
14689 @ Override
14790 public void onRequestSubmitted () {
148- requestBacklog .incrementAndGet ();
149- inflightRequests .incrementAndGet ();
91+ requestProcessing .start ();
15092 }
15193
15294 @ Override
@@ -256,84 +198,4 @@ public void onConnectSuccess(long duration, TimeUnit timeUnit) {
256198 public void onConnectStart () {
257199 tcpDelegate .onConnectStart ();
258200 }
259-
260- public long getLiveConnections () {
261- return tcpDelegate .getLiveConnections ();
262- }
263-
264- public long getConnectionCount () {
265- return tcpDelegate .getConnectionCount ();
266- }
267-
268- public long getPendingConnects () {
269- return tcpDelegate .getPendingConnects ();
270- }
271-
272- public long getFailedConnects () {
273- return tcpDelegate .getFailedConnects ();
274- }
275-
276- public long getPendingConnectionClose () {
277- return tcpDelegate .getPendingConnectionClose ();
278- }
279-
280- public long getFailedConnectionClose () {
281- return tcpDelegate .getFailedConnectionClose ();
282- }
283-
284- public long getPendingPoolAcquires () {
285- return tcpDelegate .getPendingPoolAcquires ();
286- }
287-
288- public long getFailedPoolAcquires () {
289- return tcpDelegate .getFailedPoolAcquires ();
290- }
291-
292- public long getPendingPoolReleases () {
293- return tcpDelegate .getPendingPoolReleases ();
294- }
295-
296- public long getFailedPoolReleases () {
297- return tcpDelegate .getFailedPoolReleases ();
298- }
299-
300- public long getPoolEvictions () {
301- return tcpDelegate .getPoolEvictions ();
302- }
303-
304- public long getPoolReuse () {
305- return tcpDelegate .getPoolReuse ();
306- }
307-
308- public long getPendingWrites () {
309- return tcpDelegate .getPendingWrites ();
310- }
311-
312- public long getPendingFlushes () {
313- return tcpDelegate .getPendingFlushes ();
314- }
315-
316- public long getBytesWritten () {
317- return tcpDelegate .getBytesWritten ();
318- }
319-
320- public long getBytesRead () {
321- return tcpDelegate .getBytesRead ();
322- }
323-
324- public long getFailedWrites () {
325- return tcpDelegate .getFailedWrites ();
326- }
327-
328- public long getFailedFlushes () {
329- return tcpDelegate .getFailedFlushes ();
330- }
331-
332- public long getPoolAcquires () {
333- return tcpDelegate .getPoolAcquires ();
334- }
335-
336- public long getPoolReleases () {
337- return tcpDelegate .getPoolReleases ();
338- }
339201}
0 commit comments