diff --git a/jmx-scraper/build.gradle.kts b/jmx-scraper/build.gradle.kts index 9ef9a7277..4210b65f6 100644 --- a/jmx-scraper/build.gradle.kts +++ b/jmx-scraper/build.gradle.kts @@ -1,9 +1,7 @@ plugins { application id("com.gradleup.shadow") - id("otel.java-conventions") - id("otel.publish-conventions") } @@ -92,6 +90,39 @@ tasks { } } +// This task copies the jar to a package dir for packaging. +val copyJarForPackage by tasks.registering(Copy::class) { + dependsOn(tasks.jar) + + // Clean target directory before copying + doFirst { + val targetDir = file("package/usr/local/bin") + if (targetDir.exists()) { + targetDir.deleteRecursively() + } + } + + from(tasks.jar.get().outputs.files) + into("package/usr/local/bin") + rename { "jmx-scraper.jar" } +} + +// This task creates a tarball of the package directory. +val createTarball by tasks.registering(Tar::class) { + dependsOn(copyJarForPackage) + archiveBaseName.set("opentelemetry-jmx-scraper") + archiveVersion.set(project.version.toString()) + archiveExtension.set("tar.gz") + compression = Compression.GZIP + // simply put it at the project root + destinationDirectory.set(file("./")) + + from("package") { + // preserve directory structure relative to package/ + into("/") + } +} + // Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements) with(components["java"] as AdhocComponentWithVariants) { configurations.forEach { diff --git a/jmx-scraper/package/etc/systemd/jmx-scraper.service b/jmx-scraper/package/etc/systemd/jmx-scraper.service new file mode 100644 index 000000000..1aff49ae8 --- /dev/null +++ b/jmx-scraper/package/etc/systemd/jmx-scraper.service @@ -0,0 +1,15 @@ +[Unit] +Description=OpenTelemetry JMX Scraper +After=network.target + +[Service] +Type=simple +User=jmxscraper +Group=jmxscraper +ExecStart=/usr/bin/java -jar /usr/local/bin/jmx-scraper.jar +Restart=on-failure +RestartSec=10 +WorkingDirectory=/usr/local/bin + +[Install] +WantedBy=multi-user.target diff --git a/maven-extension/README.md b/maven-extension/README.md index 91ec71744..510dc1863 100644 --- a/maven-extension/README.md +++ b/maven-extension/README.md @@ -14,6 +14,17 @@ The Maven OpenTelemetry Extension is configured using environment variables or J In the code snippets below, replace `OPENTELEMETRY_MAVEN_VERSION` with the [latest release](https://search.maven.org/search?q=g:io.opentelemetry.contrib%20AND%20a:opentelemetry-maven-extension). +## Installation +jmx-scraper is typically run as a standalone JAR file. +o use it, you generally need to download the latest JAR from the OpenTelemetry Java Contrib releases page +or retrieve it as a dependency from a Maven repository. +Once obtained, you can run it using the Java command line tool. +Please refer to [Usage](#usage). + +For systemd service, the opentelemetry-jmx-scraper-x.xx.x.tar.gz tar.gz file is available +with the JAR and a ready to install systemd service file. + + ### Adding the extension to the classpath Add the Maven OpenTelemetry Extension to `${maven.home}/lib/ext` or to the classpath using `-Dmaven.ext.class.path=`.