From 09943435a6371ac47635683e4dbc6ad435a0d5d7 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Fri, 22 Sep 2023 11:19:02 -0400 Subject: [PATCH] Better local docker instructions for misbehaving-jmx-server (#479) * Adds Dockerfile that gets the supervisor out of the picture * Adds better local-run instructions for misbehaving-jmx-server in docker * Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> * Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> * Update tools/misbehaving-jmx-server/README.md Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> --------- Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> --- tools/misbehaving-jmx-server/README.md | 20 ++++++++++++------- .../docker-compose.yaml | 19 +++++++++++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/tools/misbehaving-jmx-server/README.md b/tools/misbehaving-jmx-server/README.md index 92e073d3f..93df69e07 100644 --- a/tools/misbehaving-jmx-server/README.md +++ b/tools/misbehaving-jmx-server/README.md @@ -64,9 +64,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 \ @@ -78,10 +87,7 @@ misbehaving-jmx-server The Agent will auto discover the container and begin to collect metrics from it. -### Using Docker Compose - -```shell -$ docker compose up -``` +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](#using-docker-compose). -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