forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of JmxScraper code. Application compiles and runs as s…
…tandalone and can read config file.
- Loading branch information
Showing
12 changed files
with
610 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.jmxscraper; | ||
|
||
import io.opentelemetry.contrib.jmxscraper.config.ConfigurationException; | ||
import io.opentelemetry.contrib.jmxscraper.config.JmxScraperConfig; | ||
import io.opentelemetry.contrib.jmxscraper.config.JmxScraperConfigFactory; | ||
import io.opentelemetry.contrib.jmxscraper.jmx.JmxClient; | ||
import java.net.MalformedURLException; | ||
import java.util.Arrays; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Logger; | ||
|
||
public class JmxScraper { | ||
private static final Logger logger = Logger.getLogger(JmxScraper.class.getName()); | ||
private final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); | ||
private final JmxScraperConfig config; | ||
|
||
JmxScraper(JmxScraperConfig config) { | ||
this.config = config; | ||
|
||
try { | ||
@SuppressWarnings("unused") // TODO: Temporary | ||
JmxClient jmxClient = new JmxClient(config); | ||
} catch (MalformedURLException e) { | ||
throw new ConfigurationException("Malformed serviceUrl: ", e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("FutureReturnValueIgnored") // TODO: Temporary | ||
private void start() { | ||
exec.scheduleWithFixedDelay( | ||
() -> { | ||
logger.fine("JMX scraping triggered"); | ||
// try { | ||
// runner.run(); | ||
// } catch (Throwable e) { | ||
// logger.log(Level.SEVERE, "Error gathering JMX metrics", e); | ||
// } | ||
}, | ||
0, | ||
config.getIntervalMilliseconds(), | ||
TimeUnit.MILLISECONDS); | ||
logger.info("JMX scraping started"); | ||
} | ||
|
||
private void shutdown() { | ||
logger.info("Shutting down JmxScraper and exporting final metrics."); | ||
exec.shutdown(); | ||
} | ||
|
||
/** | ||
* Main method to create and run a {@link JmxScraper} instance. | ||
* | ||
* @param args - must be of the form "-config {jmx_config_path,'-'}" | ||
*/ | ||
public static void main(String[] args) { | ||
JmxScraperConfigFactory factory = new JmxScraperConfigFactory(); | ||
JmxScraperConfig config = factory.createConfigFromArgs(Arrays.asList(args)); | ||
|
||
JmxScraper jmxScraper = new JmxScraper(config); | ||
jmxScraper.start(); | ||
|
||
Runtime.getRuntime() | ||
.addShutdownHook( | ||
new Thread() { | ||
@Override | ||
public void run() { | ||
jmxScraper.shutdown(); | ||
} | ||
}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...aper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/ConfigurationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.jmxscraper.config; | ||
|
||
public class ConfigurationException extends RuntimeException { | ||
private static final long serialVersionUID = 0L; | ||
|
||
public ConfigurationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ConfigurationException(String message) { | ||
super(message); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.jmxscraper.config; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** This class keeps application settings */ | ||
public class JmxScraperConfig { | ||
String serviceUrl = ""; | ||
String customJmxScrapingConfig = ""; | ||
String targetSystem = ""; | ||
Set<String> targetSystems = Collections.emptySet(); | ||
int intervalMilliseconds; | ||
String metricsExporterType = ""; | ||
|
||
String otlpExporterEndpoint = ""; | ||
|
||
String prometheusExporterHost = ""; | ||
int prometheusExporterPort; | ||
|
||
String username = ""; | ||
String password = ""; | ||
String realm = ""; | ||
String remoteProfile = ""; | ||
boolean registrySsl; | ||
|
||
JmxScraperConfig() {} | ||
|
||
public String getServiceUrl() { | ||
return serviceUrl; | ||
} | ||
|
||
public String getCustomJmxScrapingConfig() { | ||
return customJmxScrapingConfig; | ||
} | ||
|
||
public String getTargetSystem() { | ||
return targetSystem; | ||
} | ||
|
||
public Set<String> getTargetSystems() { | ||
return targetSystems; | ||
} | ||
|
||
public int getIntervalMilliseconds() { | ||
return intervalMilliseconds; | ||
} | ||
|
||
public String getMetricsExporterType() { | ||
return metricsExporterType; | ||
} | ||
|
||
public String getOtlpExporterEndpoint() { | ||
return otlpExporterEndpoint; | ||
} | ||
|
||
public String getPrometheusExporterHost() { | ||
return prometheusExporterHost; | ||
} | ||
|
||
public int getPrometheusExporterPort() { | ||
return prometheusExporterPort; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getRealm() { | ||
return realm; | ||
} | ||
|
||
public String getRemoteProfile() { | ||
return remoteProfile; | ||
} | ||
|
||
public boolean isRegistrySsl() { | ||
return registrySsl; | ||
} | ||
} |
Oops, something went wrong.