1818/**
1919 * Driver class for ad-hoc experiments
2020 *
21+ * Usage:
22+ * mvn compile exec:java -Dexec.mainClass=com.wavefront.sdk.Main -Dexec.args="https://demo.wavefront.com api-token"
23+ *
2124 * @author Mori Bellamy (mori@wavefront.com).
2225 */
2326public class Main {
@@ -36,7 +39,7 @@ private static void sendMetric(WavefrontSender wavefrontSender)
3639 }};
3740 wavefrontSender .sendMetric ("new-york.power.usage" , 42422.0 , null ,
3841 "localhost" , tags );
39- System .out .println ("Sent metric: 'new-york.power.usage' to proxy " );
42+ System .out .println ("Sent metric: 'new-york.power.usage'" );
4043 }
4144
4245 private static void sendDeltaCounter (WavefrontSender wavefrontSender )
@@ -53,7 +56,7 @@ private static void sendDeltaCounter(WavefrontSender wavefrontSender)
5356 }};
5457 wavefrontSender .sendDeltaCounter ("lambda.thumbnail.generate" , 10 ,
5558 "lambda_thumbnail_service" , tags );
56- System .out .println ("Sent metric: 'lambda.thumbnail.generate' to proxy " );
59+ System .out .println ("Sent metric: 'lambda.thumbnail.generate'" );
5760 }
5861
5962 private static void sendHistogram (WavefrontSender wavefrontSender )
@@ -75,7 +78,7 @@ private static void sendHistogram(WavefrontSender wavefrontSender)
7578 wavefrontSender .sendDistribution ("request.latency" ,
7679 Arrays .asList (new Pair <>(30.0 , 20 ), new Pair <>(5.1 , 10 )), histogramGranularities ,
7780 null , "appServer1" , tags );
78- System .out .println ("Sent histogram: 'request.latency' to proxy " );
81+ System .out .println ("Sent histogram: 'request.latency'" );
7982 }
8083
8184 private static void sendTracingSpan (WavefrontSender wavefrontSender )
@@ -100,7 +103,7 @@ private static void sendTracingSpan(WavefrontSender wavefrontSender)
100103 Arrays .asList (new Pair <>("application" , "Wavefront" ),
101104 new Pair <>("service" , "test-spans" ),
102105 new Pair <>("http.method" , "GET" )), null );
103- System .out .println ("Sent tracing span: 'getAllUsers' to proxy " );
106+ System .out .println ("Sent tracing span: 'getAllUsers'" );
104107 }
105108
106109 public static void main (String [] args ) throws InterruptedException , IOException {
@@ -110,64 +113,51 @@ public static void main(String[] args) throws InterruptedException, IOException
110113 String metricsPort = args .length < 4 ? null : args [3 ];
111114 String distributionPort = args .length < 5 ? null : args [4 ];
112115 String tracingPort = args .length < 6 ? null : args [5 ];
113- String wavefrontServerWithToken = args .length < 7 ? null : args [6 ];
114- String wavefrontProxyWithPort = args .length < 8 ? null : args [7 ];
116+ String wavefrontProxyWithPort = args .length < 7 ? null : args [6 ];
115117
116- // Proxy based ingestion
117- WavefrontProxyClient .Builder builder = new WavefrontProxyClient .Builder (proxyHost );
118- if (metricsPort != null ) {
119- builder .metricsPort (Integer .parseInt (metricsPort ));
120- }
121- if (distributionPort != null ) {
122- builder .distributionPort (Integer .parseInt (distributionPort ));
123- }
124- if (tracingPort != null ) {
125- builder .tracingPort (Integer .parseInt (tracingPort ));
126- }
127- WavefrontProxyClient wavefrontProxyClient = builder .build ();
118+ String wavefrontServerWithToken = wavefrontServer .substring (0 , wavefrontServer .indexOf ("://" )+3 ) +
119+ token + "@" + wavefrontServer .substring (wavefrontServer .indexOf ("://" )+3 );
120+ System .out .println ("wavefrontServerWithToken = " + wavefrontServerWithToken );
128121
129- // Direct Data Ingestion
130- WavefrontDirectIngestionClient wavefrontDirectIngestionClient =
131- new WavefrontDirectIngestionClient .Builder (wavefrontServer , token ).build ();
132-
133- // Auto Client Negotiation
134122 WavefrontClientFactory wavefrontClientFactory = new WavefrontClientFactory ();
135- if (wavefrontServerWithToken != null ) {
136- wavefrontClientFactory .addClient (wavefrontServerWithToken );
123+ wavefrontClientFactory .addClient (wavefrontServerWithToken );
124+
125+ // DEPRECATED Client: Direct Data Ingestion
126+ // WavefrontDirectIngestionClient wavefrontDirectIngestionClient =
127+ // new WavefrontDirectIngestionClient.Builder(wavefrontServer, token).build();
128+ // wavefrontClientFactory.addClient(wavefrontDirectIngestionClient);
129+
130+ // DEPRECATED Client: Proxy based ingestion
131+ if (proxyHost != null ) {
132+ WavefrontProxyClient .Builder builder = new WavefrontProxyClient .Builder (proxyHost );
133+ if (metricsPort != null ) {
134+ builder .metricsPort (Integer .parseInt (metricsPort ));
135+ }
136+ if (distributionPort != null ) {
137+ builder .distributionPort (Integer .parseInt (distributionPort ));
138+ }
139+ if (tracingPort != null ) {
140+ builder .tracingPort (Integer .parseInt (tracingPort ));
141+ }
142+ WavefrontProxyClient wavefrontProxyClient = builder .build ();
143+ wavefrontClientFactory .addClient (wavefrontProxyClient );
137144 }
145+
138146 if (wavefrontProxyWithPort != null ) {
139147 wavefrontClientFactory .addClient (wavefrontProxyWithPort );
140148 }
141149
142- // Add existing senders
143- wavefrontClientFactory .addClient (wavefrontProxyClient );
144- wavefrontClientFactory .addClient (wavefrontDirectIngestionClient );
145-
146150 // Get back a multi client sender
147151 WavefrontSender wavefrontClient = wavefrontClientFactory .getClient ();
148152
149153 while (true ) {
150- // Send entities via Proxy
151- sendMetric (wavefrontProxyClient );
152- sendDeltaCounter (wavefrontProxyClient );
153- sendHistogram (wavefrontProxyClient );
154- sendTracingSpan (wavefrontProxyClient );
155- wavefrontProxyClient .flush ();
156-
157- // Send entities via Direct Ingestion
158- sendMetric (wavefrontDirectIngestionClient );
159- sendDeltaCounter (wavefrontDirectIngestionClient );
160- sendHistogram (wavefrontDirectIngestionClient );
161- sendTracingSpan (wavefrontDirectIngestionClient );
162-
163- // Send entities via the Multi Proxy Client
164154 sendMetric (wavefrontClient );
165155 sendDeltaCounter (wavefrontClient );
166156 sendHistogram (wavefrontClient );
167157 sendTracingSpan (wavefrontClient );
168158 wavefrontClient .flush ();
169159
170- Thread .sleep (5000 );
160+ Thread .sleep (5_000 );
171161 }
172162 }
173163}
0 commit comments