From 6e32b6e321714737cd3e5cce9448ad96fd9f8f23 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Mon, 31 Jul 2023 10:38:49 -0400 Subject: [PATCH 1/5] Adds Dockerfile that gets the supervisor out of the picture --- tools/misbehaving-jmx-server/Dockerfile.local | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tools/misbehaving-jmx-server/Dockerfile.local diff --git a/tools/misbehaving-jmx-server/Dockerfile.local b/tools/misbehaving-jmx-server/Dockerfile.local new file mode 100644 index 000000000..3a86052e7 --- /dev/null +++ b/tools/misbehaving-jmx-server/Dockerfile.local @@ -0,0 +1,27 @@ +# Use the official Maven image as the base image +FROM maven:latest AS build + +# Set the working directory to /app +WORKDIR /app + +# Copy the pom.xml file and install the dependencies +COPY pom.xml . +RUN mvn dependency:resolve + +# Copy the source code and build the JAR file +COPY src/ /app/src/ +RUN mvn clean package assembly:single + +RUN ls /app/target + +# Use the official OpenJDK image as the base image for the final image +FROM openjdk:latest AS final + +# Set the working directory to /app +WORKDIR /app + +# Copy the JAR file from the Maven image to the final image +COPY --from=build /app/target/misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar . + +# Run the supervisor class from the jar +CMD ["java", "-cp", "misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar", "org.datadog.misbehavingjmxserver.App"] From 33e760641a6c3cae3de10abf19ec3aa610a88566 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Thu, 21 Sep 2023 19:24:43 +0000 Subject: [PATCH 2/5] Adds better local-run instructions for misbehaving-jmx-server in docker --- tools/misbehaving-jmx-server/Dockerfile.local | 27 ------------------- tools/misbehaving-jmx-server/README.md | 20 +++++++++----- .../docker-compose.yaml | 19 ++++++++++--- 3 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 tools/misbehaving-jmx-server/Dockerfile.local diff --git a/tools/misbehaving-jmx-server/Dockerfile.local b/tools/misbehaving-jmx-server/Dockerfile.local deleted file mode 100644 index 3a86052e7..000000000 --- a/tools/misbehaving-jmx-server/Dockerfile.local +++ /dev/null @@ -1,27 +0,0 @@ -# Use the official Maven image as the base image -FROM maven:latest AS build - -# Set the working directory to /app -WORKDIR /app - -# Copy the pom.xml file and install the dependencies -COPY pom.xml . -RUN mvn dependency:resolve - -# Copy the source code and build the JAR file -COPY src/ /app/src/ -RUN mvn clean package assembly:single - -RUN ls /app/target - -# Use the official OpenJDK image as the base image for the final image -FROM openjdk:latest AS final - -# Set the working directory to /app -WORKDIR /app - -# Copy the JAR file from the Maven image to the final image -COPY --from=build /app/target/misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar . - -# Run the supervisor class from the jar -CMD ["java", "-cp", "misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar", "org.datadog.misbehavingjmxserver.App"] diff --git a/tools/misbehaving-jmx-server/README.md b/tools/misbehaving-jmx-server/README.md index a749b6166..c3468c150 100644 --- a/tools/misbehaving-jmx-server/README.md +++ b/tools/misbehaving-jmx-server/README.md @@ -52,9 +52,18 @@ There are a couple of ways you can get the Agent to pull metrics from this test Copy `misbehaving-jmxfetch-conf.yaml` to `/etc/datadog-agent/conf.d/` and just run the `with-dependencies` jar created by Maven. You will need to restart the Agent to pick up the config. +### Using Docker Compose + +```shell +$ docker compose up +``` + +The Agent will auto discover the container and begin to collect metrics from it. + ### Using Docker -After building the `misbehaving-jmx-server` you can simply run: +If your container's IP is directly +accessible by your Agent, you can use the following run command and use AD. ```shell $ docker run \ @@ -66,10 +75,7 @@ misbehaving-jmx-server The Agent will auto discover the container and begin to collect metrics from it. -### Using Docker Compose +Note that this implicitly sets the `RMI_HOSTNAME` to `localhost` which is where +the host port mapping comes into play. If this is giving you trouble, consider +using the docker-compose setup above. -```shell -$ docker compose up -``` - -The Agent will auto discover the container and begin to collect metrics from it. diff --git a/tools/misbehaving-jmx-server/docker-compose.yaml b/tools/misbehaving-jmx-server/docker-compose.yaml index 0c7062e78..200444826 100644 --- a/tools/misbehaving-jmx-server/docker-compose.yaml +++ b/tools/misbehaving-jmx-server/docker-compose.yaml @@ -2,11 +2,24 @@ version: "3.9" services: - - test-server: + # The docker compose service name is used as the hostname for the misbehaving-jmx-server + # Note it is in the entrypoint as the --rmi-host and in the AD label as the hostname + # that the Agent should reach out to. + jmx-test-server: build: context: . + # Override entrypoint to specify the docker-compose service name as the RMI host + entrypoint: ["java", "-cp", "misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar", "org.datadog.misbehavingjmxserver.App", "--rmi-host", "jmx-test-server"] ports: - "1099:1099" labels: - com.datadoghq.ad.checks: '{"misbehaving":{"init_config":{"is_jmx":true},"instances":[{"host":"%%host%%","port":"1099","collect_default_jvm_metrics":false,"max_returned_metrics":300000,"conf":[{"include":{"domain":"Bohnanza"}}]}]}}' + com.datadoghq.ad.checks: '{"misbehaving":{"init_config":{"is_jmx":true},"instances":[{"host":"jmx-test-server","port":"1099","collect_default_jvm_metrics":false,"max_returned_metrics":300000,"conf":[{"include":{"domain":"Bohnanza"}}]}]}}' + datadog: + image: datadog/agent:7-jmx + pid: host + environment: + - DD_API_KEY=000000001 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /proc/:/host/proc/:ro + - /sys/fs/cgroup:/host/sys/fs/cgroup:ro From 5ad03f12ead796956e920db6d98de5682351cb86 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Fri, 22 Sep 2023 15:41:32 +0200 Subject: [PATCH 3/5] Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> --- tools/misbehaving-jmx-server/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/misbehaving-jmx-server/README.md b/tools/misbehaving-jmx-server/README.md index c3468c150..c3ce48847 100644 --- a/tools/misbehaving-jmx-server/README.md +++ b/tools/misbehaving-jmx-server/README.md @@ -63,7 +63,7 @@ The Agent will auto discover the container and begin to collect metrics from it. ### Using Docker If your container's IP is directly -accessible by your Agent, you can use the following run command and use AD. +accessible by your Agent, you can use the following `run` command and use AD. ```shell $ docker run \ From eb420b33143121a71a92bcc0a98d80bcc2edc81b Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Fri, 22 Sep 2023 15:41:42 +0200 Subject: [PATCH 4/5] Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> --- tools/misbehaving-jmx-server/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/misbehaving-jmx-server/README.md b/tools/misbehaving-jmx-server/README.md index c3ce48847..dff573e28 100644 --- a/tools/misbehaving-jmx-server/README.md +++ b/tools/misbehaving-jmx-server/README.md @@ -77,5 +77,5 @@ The Agent will auto discover the container and begin to collect metrics from it. Note that this implicitly sets the `RMI_HOSTNAME` to `localhost` which is where the host port mapping comes into play. If this is giving you trouble, consider -using the docker-compose setup above. +using the [docker-compose setup](#using-docker-compose). From 7c5772b3ebd38f803a09fc51a5c1cbd750722cde Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Fri, 22 Sep 2023 15:41:49 +0200 Subject: [PATCH 5/5] Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> --- tools/misbehaving-jmx-server/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/misbehaving-jmx-server/README.md b/tools/misbehaving-jmx-server/README.md index dff573e28..f383a7ba5 100644 --- a/tools/misbehaving-jmx-server/README.md +++ b/tools/misbehaving-jmx-server/README.md @@ -58,7 +58,7 @@ You will need to restart the Agent to pick up the config. $ docker compose up ``` -The Agent will auto discover the container and begin to collect metrics from it. +The Agent will auto-discover the container and begin to collect metrics from it. ### Using Docker