1616import java .nio .file .Paths ;
1717import java .util .Arrays ;
1818import java .util .List ;
19- import java .util .Objects ;
2019import java .util .Properties ;
2120import java .util .logging .Logger ;
2221import javax .management .MBeanServerConnection ;
@@ -38,11 +37,12 @@ public class JmxScraper {
3837 */
3938 @ SuppressWarnings ({"SystemOut" , "SystemExitOutsideMain" })
4039 public static void main (String [] args ) {
41- JmxScraperConfig config ;
42- JmxScraper jmxScraper = null ;
4340 try {
44- config = JmxScraper .createConfigFromArgs (Arrays .asList (args ));
45- jmxScraper = new JmxScraper (config );
41+ JmxScraperConfig config = JmxScraper .createConfigFromArgs (Arrays .asList (args ));
42+ // TODO: depend on instrumentation 2.9.0 snapshot
43+ // service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), config.getIntervalMilliseconds());
44+ JmxScraper jmxScraper = new JmxScraper (JmxRemoteClient .createNew (config .getServiceUrl ()));
45+ jmxScraper .start ();
4646
4747 } catch (ArgumentsParsingException e ) {
4848 System .err .println ("ERROR: " + e .getMessage ());
@@ -53,14 +53,11 @@ public static void main(String[] args) {
5353 } catch (ConfigurationException e ) {
5454 System .err .println (e .getMessage ());
5555 System .exit (1 );
56- }
57-
58- try {
59- Objects .requireNonNull (jmxScraper ).start ();
6056 } catch (IOException e ) {
6157 System .err .println ("Unable to connect " + e .getMessage ());
6258 System .exit (2 );
6359 }
60+
6461 }
6562
6663 /**
@@ -112,15 +109,8 @@ private static Properties loadPropertiesFromPath(String path)
112109 }
113110 }
114111
115- JmxScraper (JmxScraperConfig config ) throws ConfigurationException {
116- String serviceUrl = config .getServiceUrl ();
117- int interval = config .getIntervalMilliseconds ();
118- if (interval < 0 ) {
119- throw new ConfigurationException ("interval must be positive" );
120- }
121- this .client = JmxRemoteClient .createNew (serviceUrl );
122- // TODO: depend on instrumentation 2.9.0 snapshot
123- // this.service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), interval);
112+ JmxScraper (JmxRemoteClient client ) {
113+ this .client = client ;
124114 }
125115
126116 private void start () throws IOException {
0 commit comments