11/*
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.
1512 */
16- package io .reactivesocket .loadbalancer . servo ;
13+ package io .reactivesocket .spectator ;
1714
1815import io .reactivesocket .Payload ;
1916import 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 ;
2219import io .reactivesocket .util .ReactiveSocketProxy ;
2320import org .reactivestreams .Publisher ;
2421import org .reactivestreams .Subscriber ;
2926/**
3027 * An implementation of {@link ReactiveSocket} that sends metrics to Servo
3128 */
32- public class ServoMetricsReactiveSocket extends ReactiveSocketProxy {
29+ public class InstrumentedReactiveSocket extends ReactiveSocketProxy {
3330 final ThreadLocalAdderCounter success ;
3431 final ThreadLocalAdderCounter failure ;
35- final HdrHistogramServoTimer timer ;
32+ final HdrHistogramPercentileTimer timer ;
3633
3734 private class RecordingSubscriber <T > implements Subscriber <T > {
3835 private final Subscriber <T > child ;
@@ -66,11 +63,11 @@ public void onComplete() {
6663 }
6764 }
6865
69- public ServoMetricsReactiveSocket (ReactiveSocket child , String prefix ) {
66+ public InstrumentedReactiveSocket (ReactiveSocket child , String prefix ) {
7067 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 );
7471 }
7572
7673 @ Override
@@ -118,13 +115,13 @@ public String histrogramToString() {
118115
119116 StringBuilder s = new StringBuilder ();
120117 s .append (String .format ("%-12s%-12s\n " ,"Percentile" ,"Latency" ));
121- s .append (String . format ( "=========================\n " ) );
118+ s .append ("=========================\n " );
122119 s .append (String .format ("%-12s%dms\n " ,"50%" ,NANOSECONDS .toMillis (timer .getP50 ())));
123120 s .append (String .format ("%-12s%dms\n " ,"90%" ,NANOSECONDS .toMillis (timer .getP90 ())));
124121 s .append (String .format ("%-12s%dms\n " ,"99%" ,NANOSECONDS .toMillis (timer .getP99 ())));
125122 s .append (String .format ("%-12s%dms\n " ,"99.9%" ,NANOSECONDS .toMillis (timer .getP99_9 ())));
126123 s .append (String .format ("%-12s%dms\n " ,"99.99%" ,NANOSECONDS .toMillis (timer .getP99_99 ())));
127- s .append (String . format ( "-------------------------\n " ) );
124+ s .append ("-------------------------\n " );
128125 s .append (String .format ("%-12s%dms\n " ,"min" ,NANOSECONDS .toMillis (timer .getMin ())));
129126 s .append (String .format ("%-12s%dms\n " ,"max" ,NANOSECONDS .toMillis (timer .getMax ())));
130127 s .append (String .format ("%-12s%d (%.0f%%)\n " ,"success" ,successCount ,100.0 *successCount /totalCount ));
@@ -133,7 +130,7 @@ public String histrogramToString() {
133130 return s .toString ();
134131 }
135132
136- private long recordStart () {
133+ private static long recordStart () {
137134 return System .nanoTime ();
138135 }
139136
0 commit comments