Skip to content

Commit

Permalink
Initial commit of JmxScraper code. Application compiles and runs as s…
Browse files Browse the repository at this point in the history
…tandalone and can read config file.
  • Loading branch information
robsunday committed Sep 10, 2024
1 parent 5a82aac commit 165fcb8
Show file tree
Hide file tree
Showing 12 changed files with 610 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ components:
- sfriberg
jmx-metrics:
- breedx-splk
jmx-scraper:
- breedx-splk
- robsunday
- sylvainjuge
maven-extension:
- cyrille-leclerc
- kenfinnigan
Expand Down
2 changes: 1 addition & 1 deletion jmx-scrapper/README.md → jmx-scraper/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JMX Metric Scrapper
# JMX Metric Scraper

This utility provides a way to query JMX metrics and export them to an OTLP endpoint.
The JMX MBeans and their metrics mapping is defined in YAML.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ plugins {
id("otel.publish-conventions")
}

description = "JMX metrics scrapper"
otelJava.moduleName.set("io.opentelemetry.contrib.jmxscrapper")
description = "JMX metrics scraper"
otelJava.moduleName.set("io.opentelemetry.contrib.jmxscraper")

application.mainClass.set("io.opentelemetry.contrib.jmxscrapper.JmxMetrics")
application.mainClass.set("io.opentelemetry.contrib.jmxscraper.JmxScraper")

dependencies {
implementation("io.opentelemetry:opentelemetry-api")
Expand Down
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();
}
});
}
}
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);
}
}
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;
}
}
Loading

0 comments on commit 165fcb8

Please sign in to comment.