77
88import com .amazonaws .util .EC2MetadataUtils ;
99import com .codahale .metrics .Meter ;
10- import com .codahale .metrics .MetricFilter ;
1110import com .codahale .metrics .MetricRegistry ;
1211import com .codahale .metrics .Timer ;
13- import com .codahale .metrics .graphite .GraphiteReporter ;
1412import com .codahale .metrics .jvm .CachedThreadStatesGaugeSet ;
1513import com .codahale .metrics .jvm .GarbageCollectorMetricSet ;
1614import com .codahale .metrics .jvm .MemoryUsageGaugeSet ;
1715import com .codahale .metrics .logback .InstrumentedAppender ;
1816
1917import ch .qos .logback .classic .LoggerContext ;
20- import okhttp3 .OkHttpClient ;
2118
2219// {{start:metrics}}
2320public class Metrics {
@@ -37,24 +34,8 @@ public class Metrics {
3734 metrics .start ();
3835 root .addAppender (metrics );
3936
40-
41- // Graphite reporter to Grafana Cloud
42- OkHttpClient client = new OkHttpClient .Builder ()
43- //.addNetworkInterceptor(HttpClient.getLoggingInterceptor())
44- .build ();
45-
46- String graphiteHost = Configs .properties ().getString ("metrics.graphite.host" );
47- String grafanaApiKey = Configs .properties ().getString ("metrics.grafana.api_key" );
48- final GraphiteHttpSender graphite = new GraphiteHttpSender (client , graphiteHost , grafanaApiKey );
49- final GraphiteReporter reporter = GraphiteReporter .forRegistry (registry )
50- .prefixedWith (metricPrefix ("stubbornjava" ))
51- .convertRatesTo (TimeUnit .MINUTES )
52- .convertDurationsTo (TimeUnit .MILLISECONDS )
53- .filter (MetricFilter .ALL )
54- .build (graphite );
55- reporter .start (10 , TimeUnit .SECONDS );
56-
5737 // Register reporters here.
38+ MetricsReporters .startReporters (registry );
5839 }
5940
6041 public static MetricRegistry registry () {
@@ -69,7 +50,7 @@ public static Meter meter(String first, String... keys) {
6950 return registry .meter (MetricRegistry .name (first , keys ));
7051 }
7152
72- private static String metricPrefix (String app ) {
53+ static String metricPrefix (String app ) {
7354 Env env = Env .get ();
7455 String host = env == Env .LOCAL ? "localhost" : getHost ();
7556 String prefix = MetricRegistry .name (app , env .getName (), host );
0 commit comments