31
31
import org .slf4j .Logger ;
32
32
import org .slf4j .LoggerFactory ;
33
33
34
+ import lombok .extern .slf4j .Slf4j ;
35
+
36
+ @ Slf4j
34
37
public class HTTPMetricsServer {
35
38
36
39
private static final Logger HTTP_LOGGER = LoggerFactory .getLogger ("httpMonitor" );
37
40
38
- private static final Logger LOGGER = LoggerFactory .getLogger (HTTPMetricsServer .class );
39
-
40
41
private final transient EventMeshHTTPServer eventMeshHTTPServer ;
41
42
42
43
private final transient List <MetricsRegistry > metricsRegistries ;
@@ -47,24 +48,24 @@ public HTTPMetricsServer(EventMeshHTTPServer eventMeshHTTPServer, List<MetricsRe
47
48
this .eventMeshHTTPServer = eventMeshHTTPServer ;
48
49
this .metricsRegistries = metricsRegistries ;
49
50
this .summaryMetrics = new HttpSummaryMetrics (
50
- eventMeshHTTPServer .batchMsgExecutor ,
51
- eventMeshHTTPServer .sendMsgExecutor ,
52
- eventMeshHTTPServer .pushMsgExecutor ,
53
- eventMeshHTTPServer .getHttpRetryer ().getFailedQueue ());
51
+ eventMeshHTTPServer .batchMsgExecutor ,
52
+ eventMeshHTTPServer .sendMsgExecutor ,
53
+ eventMeshHTTPServer .pushMsgExecutor ,
54
+ eventMeshHTTPServer .getHttpRetryer ().getFailedQueue ());
54
55
}
55
56
56
57
public void init () throws Exception {
57
58
metricsRegistries .forEach (MetricsRegistry ::start );
58
- if (LOGGER .isInfoEnabled ()) {
59
- LOGGER .info ("HTTPMetricsServer initialized......" );
59
+ if (log .isInfoEnabled ()) {
60
+ log .info ("HTTPMetricsServer initialized......" );
60
61
}
61
62
}
62
63
63
64
public void start () throws Exception {
64
65
metricsRegistries .forEach (metricsRegistry -> {
65
66
metricsRegistry .register (summaryMetrics );
66
- if (LOGGER .isInfoEnabled ()) {
67
- LOGGER .info ("Register httpMetrics to " + metricsRegistry .getClass ().getName ());
67
+ if (log .isInfoEnabled ()) {
68
+ log .info ("Register httpMetrics to " + metricsRegistry .getClass ().getName ());
68
69
}
69
70
});
70
71
metricsSchedule .scheduleAtFixedRate (() -> {
@@ -74,28 +75,28 @@ public void start() throws Exception {
74
75
summaryMetrics .snapshotSendMsgTPS ();
75
76
summaryMetrics .snapshotPushMsgTPS ();
76
77
} catch (Exception ex ) {
77
- LOGGER .warn ("eventMesh snapshot tps metrics err" , ex );
78
+ log .warn ("eventMesh snapshot tps metrics err" , ex );
78
79
}
79
80
}, 0 , 1000 , TimeUnit .MILLISECONDS );
80
81
81
82
metricsSchedule .scheduleAtFixedRate (() -> {
82
83
try {
83
84
logPrintServerMetrics ();
84
85
} catch (Exception ex ) {
85
- LOGGER .warn ("eventMesh print metrics err" , ex );
86
+ log .warn ("eventMesh print metrics err" , ex );
86
87
}
87
88
}, 1000 , 30 * 1000 , TimeUnit .MILLISECONDS );
88
89
89
- if (LOGGER .isInfoEnabled ()) {
90
- LOGGER .info ("HTTPMetricsServer started......" );
90
+ if (log .isInfoEnabled ()) {
91
+ log .info ("HTTPMetricsServer started......" );
91
92
}
92
93
}
93
94
94
95
public void shutdown () throws Exception {
95
96
metricsSchedule .shutdown ();
96
97
metricsRegistries .forEach (MetricsRegistry ::showdown );
97
- if (LOGGER .isInfoEnabled ()) {
98
- LOGGER .info ("HTTPMetricsServer shutdown......" );
98
+ if (log .isInfoEnabled ()) {
99
+ log .info ("HTTPMetricsServer shutdown......" );
99
100
}
100
101
}
101
102
@@ -116,71 +117,72 @@ private void logPrintServerMetrics() {
116
117
if (HTTP_LOGGER .isInfoEnabled ()) {
117
118
HTTP_LOGGER .info ("===========================================SERVER METRICS==================================================" );
118
119
119
- HTTP_LOGGER .info (String . format ( HttpSummaryMetrics . EVENTMESH_MONITOR_FORMAT_HTTP ,
120
- summaryMetrics .maxHTTPTPS (),
121
- summaryMetrics .avgHTTPTPS (),
122
- summaryMetrics .maxHTTPCost (),
123
- summaryMetrics .avgHTTPCost (),
124
- summaryMetrics .avgHTTPBodyDecodeCost (),
125
- summaryMetrics .getHttpDiscard () ));
120
+ HTTP_LOGGER .info ("maxHTTPTPS: {}, avgHTTPTPS: {}, maxHTTPCOST: {}, avgHTTPCOST: {}, avgHTTPBodyDecodeCost: {}, httpDiscard: {}" ,
121
+ summaryMetrics .maxHTTPTPS (),
122
+ summaryMetrics .avgHTTPTPS (),
123
+ summaryMetrics .maxHTTPCost (),
124
+ summaryMetrics .avgHTTPCost (),
125
+ summaryMetrics .avgHTTPBodyDecodeCost (),
126
+ summaryMetrics .getHttpDiscard ());
126
127
}
127
128
128
129
summaryMetrics .httpStatInfoClear ();
129
130
130
131
if (HTTP_LOGGER .isInfoEnabled ()) {
131
- HTTP_LOGGER .info (String . format ( HttpSummaryMetrics . EVENTMESH_MONITOR_FORMAT_BATCHSENDMSG ,
132
- summaryMetrics .maxSendBatchMsgTPS (),
133
- summaryMetrics .avgSendBatchMsgTPS (),
134
- summaryMetrics .getSendBatchMsgNumSum (),
135
- summaryMetrics .getSendBatchMsgFailNumSum (),
136
- summaryMetrics .getSendBatchMsgFailRate (),
137
- summaryMetrics .getSendBatchMsgDiscardNumSum ()
138
- )) ;
132
+ HTTP_LOGGER .info ("maxBatchSendMsgTPS: {}, avgBatchSendMsgTPS: {}, sum: {}. sumFail: {}, sumFailRate: {}, discard : {}" ,
133
+ summaryMetrics .maxSendBatchMsgTPS (),
134
+ summaryMetrics .avgSendBatchMsgTPS (),
135
+ summaryMetrics .getSendBatchMsgNumSum (),
136
+ summaryMetrics .getSendBatchMsgFailNumSum (),
137
+ summaryMetrics .getSendBatchMsgFailRate (),
138
+ summaryMetrics .getSendBatchMsgDiscardNumSum ()
139
+ );
139
140
}
140
141
141
142
summaryMetrics .cleanSendBatchStat ();
142
143
143
144
if (HTTP_LOGGER .isInfoEnabled ()) {
144
- HTTP_LOGGER .info (String . format ( HttpSummaryMetrics . EVENTMESH_MONITOR_FORMAT_SENDMSG ,
145
- summaryMetrics .maxSendMsgTPS (),
146
- summaryMetrics .avgSendMsgTPS (),
147
- summaryMetrics .getSendMsgNumSum (),
148
- summaryMetrics .getSendMsgFailNumSum (),
149
- summaryMetrics .getSendMsgFailRate (),
150
- summaryMetrics .getReplyMsgNumSum (),
151
- summaryMetrics .getReplyMsgFailNumSum ()
152
- )) ;
145
+ HTTP_LOGGER .info ("maxSendMsgTPS: {}, avgSendMsgTPS: {}, sum: {}, sumFail: {}, sumFailRate: {}, replyMsg: {}, replyFail: {}" ,
146
+ summaryMetrics .maxSendMsgTPS (),
147
+ summaryMetrics .avgSendMsgTPS (),
148
+ summaryMetrics .getSendMsgNumSum (),
149
+ summaryMetrics .getSendMsgFailNumSum (),
150
+ summaryMetrics .getSendMsgFailRate (),
151
+ summaryMetrics .getReplyMsgNumSum (),
152
+ summaryMetrics .getReplyMsgFailNumSum ()
153
+ );
153
154
}
154
155
155
156
summaryMetrics .cleanSendMsgStat ();
156
157
157
158
if (HTTP_LOGGER .isInfoEnabled ()) {
158
- HTTP_LOGGER .info (String .format (HttpSummaryMetrics .EVENTMESH_MONITOR_FORMAT_PUSHMSG ,
159
- summaryMetrics .maxPushMsgTPS (),
160
- summaryMetrics .avgPushMsgTPS (),
161
- summaryMetrics .getHttpPushMsgNumSum (),
162
- summaryMetrics .getHttpPushFailNumSum (),
163
- summaryMetrics .getHttpPushMsgFailRate (),
164
- summaryMetrics .maxHTTPPushLatency (),
165
- summaryMetrics .avgHTTPPushLatency ()
166
- ));
159
+ HTTP_LOGGER .info (
160
+ "maxPushMsgTPS: {}, avgPushMsgTPS: {}, sum: {}, sumFail: {}, sumFailRate: {}, maxClientLatency: {}, avgClientLatency: {}" ,
161
+ summaryMetrics .maxPushMsgTPS (),
162
+ summaryMetrics .avgPushMsgTPS (),
163
+ summaryMetrics .getHttpPushMsgNumSum (),
164
+ summaryMetrics .getHttpPushFailNumSum (),
165
+ summaryMetrics .getHttpPushMsgFailRate (),
166
+ summaryMetrics .maxHTTPPushLatency (),
167
+ summaryMetrics .avgHTTPPushLatency ()
168
+ );
167
169
}
168
170
169
171
summaryMetrics .cleanHttpPushMsgStat ();
170
172
171
173
if (HTTP_LOGGER .isInfoEnabled ()) {
172
- HTTP_LOGGER .info (String . format ( HttpSummaryMetrics . EVENTMESH_MONITOR_FORMAT_BLOCKQ ,
173
- eventMeshHTTPServer .getBatchMsgExecutor ().getQueue ().size (),
174
- eventMeshHTTPServer .getSendMsgExecutor ().getQueue ().size (),
175
- eventMeshHTTPServer .getPushMsgExecutor ().getQueue ().size (),
176
- eventMeshHTTPServer .getHttpRetryer ().size () ));
174
+ HTTP_LOGGER .info ("batchMsgQ: {}, sendMsgQ: {}, pushMsgQ: {}, httpRetryQ: {}" ,
175
+ eventMeshHTTPServer .getBatchMsgExecutor ().getQueue ().size (),
176
+ eventMeshHTTPServer .getSendMsgExecutor ().getQueue ().size (),
177
+ eventMeshHTTPServer .getPushMsgExecutor ().getQueue ().size (),
178
+ eventMeshHTTPServer .getHttpRetryer ().size ());
177
179
}
178
180
179
181
if (HTTP_LOGGER .isInfoEnabled ()) {
180
- HTTP_LOGGER .info (String . format ( HttpSummaryMetrics . EVENTMESH_MONITOR_FORMAT_MQ_CLIENT ,
181
- summaryMetrics .avgBatchSendMsgCost (),
182
- summaryMetrics .avgSendMsgCost (),
183
- summaryMetrics .avgReplyMsgCost () ));
182
+ HTTP_LOGGER .info ("batchAvgSend2MQCost: {}, avgSend2MQCost: {}, avgReply2MQCost: {}" ,
183
+ summaryMetrics .avgBatchSendMsgCost (),
184
+ summaryMetrics .avgSendMsgCost (),
185
+ summaryMetrics .avgReplyMsgCost ());
184
186
}
185
187
summaryMetrics .send2MQStatInfoClear ();
186
188
}
0 commit comments