1
1
/*
2
- * Copyright 2016 Netflix, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
2
+ * Copyright 2017 Netflix, Inc.
3
+ * <p>
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5
+ * the License. You may obtain a copy of the License at
6
+ * <p>
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ * <p>
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11
+ * specific language governing permissions and limitations under the License.
15
12
*/
16
- package io .reactivesocket .loadbalancer . servo ;
13
+ package io .reactivesocket .spectator ;
17
14
18
15
import io .reactivesocket .Payload ;
19
16
import io .reactivesocket .ReactiveSocket ;
20
- import io .reactivesocket .loadbalancer . servo . internal .HdrHistogramServoTimer ;
21
- import io .reactivesocket .loadbalancer . servo .internal .ThreadLocalAdderCounter ;
17
+ import io .reactivesocket .spectator . internal .HdrHistogramPercentileTimer ;
18
+ import io .reactivesocket .spectator .internal .ThreadLocalAdderCounter ;
22
19
import io .reactivesocket .util .ReactiveSocketProxy ;
23
20
import org .reactivestreams .Publisher ;
24
21
import org .reactivestreams .Subscriber ;
29
26
/**
30
27
* An implementation of {@link ReactiveSocket} that sends metrics to Servo
31
28
*/
32
- public class ServoMetricsReactiveSocket extends ReactiveSocketProxy {
29
+ public class InstrumentedReactiveSocket extends ReactiveSocketProxy {
33
30
final ThreadLocalAdderCounter success ;
34
31
final ThreadLocalAdderCounter failure ;
35
- final HdrHistogramServoTimer timer ;
32
+ final HdrHistogramPercentileTimer timer ;
36
33
37
34
private class RecordingSubscriber <T > implements Subscriber <T > {
38
35
private final Subscriber <T > child ;
@@ -66,11 +63,11 @@ public void onComplete() {
66
63
}
67
64
}
68
65
69
- public ServoMetricsReactiveSocket (ReactiveSocket child , String prefix ) {
66
+ public InstrumentedReactiveSocket (ReactiveSocket child , String prefix ) {
70
67
super (child );
71
- this . success = ThreadLocalAdderCounter . newThreadLocalAdderCounter ( prefix + "_success" );
72
- this . failure = ThreadLocalAdderCounter . newThreadLocalAdderCounter ( prefix + "_failure" );
73
- this . timer = HdrHistogramServoTimer . newInstance ( prefix + "_timer" );
68
+ success = new ThreadLocalAdderCounter ( "success" , prefix );
69
+ failure = new ThreadLocalAdderCounter ( "failure" , prefix );
70
+ timer = new HdrHistogramPercentileTimer ( "latency" , prefix );
74
71
}
75
72
76
73
@ Override
@@ -118,13 +115,13 @@ public String histrogramToString() {
118
115
119
116
StringBuilder s = new StringBuilder ();
120
117
s .append (String .format ("%-12s%-12s\n " ,"Percentile" ,"Latency" ));
121
- s .append (String . format ( "=========================\n " ) );
118
+ s .append ("=========================\n " );
122
119
s .append (String .format ("%-12s%dms\n " ,"50%" ,NANOSECONDS .toMillis (timer .getP50 ())));
123
120
s .append (String .format ("%-12s%dms\n " ,"90%" ,NANOSECONDS .toMillis (timer .getP90 ())));
124
121
s .append (String .format ("%-12s%dms\n " ,"99%" ,NANOSECONDS .toMillis (timer .getP99 ())));
125
122
s .append (String .format ("%-12s%dms\n " ,"99.9%" ,NANOSECONDS .toMillis (timer .getP99_9 ())));
126
123
s .append (String .format ("%-12s%dms\n " ,"99.99%" ,NANOSECONDS .toMillis (timer .getP99_99 ())));
127
- s .append (String . format ( "-------------------------\n " ) );
124
+ s .append ("-------------------------\n " );
128
125
s .append (String .format ("%-12s%dms\n " ,"min" ,NANOSECONDS .toMillis (timer .getMin ())));
129
126
s .append (String .format ("%-12s%dms\n " ,"max" ,NANOSECONDS .toMillis (timer .getMax ())));
130
127
s .append (String .format ("%-12s%d (%.0f%%)\n " ,"success" ,successCount ,100.0 *successCount /totalCount ));
@@ -133,7 +130,7 @@ public String histrogramToString() {
133
130
return s .toString ();
134
131
}
135
132
136
- private long recordStart () {
133
+ private static long recordStart () {
137
134
return System .nanoTime ();
138
135
}
139
136
0 commit comments