### Install via Homebrew Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Install the proxy and agent via Homebrew on macOS and Linux. Each formula installs the Java it runs on (openjdk@25) and puts its command on your PATH. ```bash brew install pambrose/tap/prometheus-proxy brew install pambrose/tap/prometheus-agent ``` -------------------------------- ### Clone and run the demo with make commands Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/basics/README.md Clone the repository at release 4.7.0 and run the demo from its directory. `make up` pulls images and starts everything, `make tour` walks through the guided tour, and `make down` stops and removes containers, network, and volume. The first `make up` takes a few minutes to pull images; subsequent starts are under a minute. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/basics make up # pulls the images, starts everything, and prints the URLs make tour # walks through the guided tour below, pausing before each step make down # stops it and removes its containers, network, and volume ``` -------------------------------- ### Load configuration from URL or local file Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/ConfigExamples.txt Shows how to start the agent with a configuration file, either from a URL or a local path. ```bash java -jar prometheus-agent.jar \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf ``` ```bash java -jar prometheus-agent.jar --config /etc/prometheus-proxy/agent.conf ``` -------------------------------- ### Install and run via Homebrew Source: https://github.com/pambrose/prometheus-proxy/blob/master/llms.txt Install the proxy and agent formulas, each pulling openjdk@25 as a dependency. Use brew services to run them in the background, started at login, with configs in $(brew --prefix)/etc/prometheus-{proxy,agent}.conf and logs in $(brew --prefix)/var/log/.log. ```bash # Each formula installs openjdk@25 as a dependency brew install pambrose/tap/prometheus-proxy prometheus-proxy brew install pambrose/tap/prometheus-agent prometheus-agent --proxy mymachine.local --config myapps.conf # Or run them in the background as services, started again at every login, configured in # $(brew --prefix)/etc/prometheus-{proxy,agent}.conf and logging to $(brew --prefix)/var/log/.log brew services start prometheus-proxy brew services start prometheus-agent brew services restart prometheus-agent # pick up an edited config brew services stop prometheus-agent # stop, and no longer start at login ``` -------------------------------- ### Clone and run the Spring Boot demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/spring-boot/README.md Commands to clone the release branch, start the demo, run the guided tour, and stop it. Requires Docker with Compose v2, git, curl, make, and bash. The first build downloads Maven dependencies and takes a few minutes. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/spring-boot make up # builds the roastery, starts everything, prints the URLs make tour # the guided tour, about 11 minutes make down # stops it and removes its containers and network ``` -------------------------------- ### Create network and start proxy and agent containers Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Sets up a Docker network, starts the proxy with metrics enabled, starts the agent with a config URL, and scrapes metrics through the proxy. The agent reaches the proxy by container name via PROXY_HOSTNAME; the proxy needs METRICS_ENABLED=true for the agent to fetch its metrics. Containers run in the foreground until Ctrl+C. ```bash # Create a network for the two containers docker network create prometheus-proxy-net # Start proxy, with its metrics enabled docker run --rm --name prometheus-proxy --network prometheus-proxy-net \ -p 8080:8080 -p 50051:50051 \ --env METRICS_ENABLED=true \ pambrose/prometheus-proxy:4.7.0 # Start agent, in another terminal docker run --rm --network prometheus-proxy-net \ --env PROXY_HOSTNAME=prometheus-proxy \ --env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \ pambrose/prometheus-agent:4.7.0 # Scrape the proxy's and the agent's own metrics through the proxy curl http://localhost:8080/proxy_metrics curl http://localhost:8080/agent_metrics ``` -------------------------------- ### Clone and run the basics demo with make commands Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Clones the prometheus-proxy repository at version 4.7.0 and runs the basics demo. `make up` pulls images, starts everything, and prints URLs; `make tour` runs the guided tour; `make down` stops the demo and removes its containers. Demos use different ports so they can run side by side. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/basics make up # pulls the images, starts everything, and prints the URLs make tour # the guided tour make down # stops the demo and removes its containers ``` -------------------------------- ### Start the agent with --proxy option Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Alternative way to start the agent using the --proxy option instead of -Dagent.proxy.hostname. Runs in the foreground until Ctrl+C. ```bash java -jar prometheus-agent.jar \ --proxy mymachine.local \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### Install agent with Helm Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Installs the agent in the cluster whose services it scrapes, using the agent.conf file. proxy.hostname is required and takes precedence over the one in agent.conf. Point each url at the service's cluster DNS name. ```bash helm install prometheus-agent ./charts/prometheus-agent \ --set proxy.hostname=proxy-host.example.com:50051 \ --set-file config=agent.conf ``` -------------------------------- ### Clone and run demo commands Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/kubernetes/README.md Clone the repository at the latest release and run the demo's commands from its own directory. `make up` creates both clusters, installs everything, and prints the URLs; `make tour` walks through the guided tour; `make down` deletes both clusters. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/kubernetes make up # creates both clusters, installs everything, and prints the URLs make tour # walks through the guided tour below, pausing before each step make down # deletes both clusters ``` -------------------------------- ### Create network and run proxy container with metrics enabled Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/DockerExamples.txt Sets up a Docker network and starts the prometheus-proxy container on it, exposing ports 8080 and 50051 and enabling metrics via METRICS_ENABLED=true. Use this as the first step in a basic proxy-agent setup. ```bash # Create a network for the proxy and agent containers: docker network create prometheus-proxy-net # Start a proxy container on it, with its metrics enabled: docker run --rm --name prometheus-proxy --network prometheus-proxy-net \ -p 8080:8080 -p 50051:50051 \ --env METRICS_ENABLED=true \ pambrose/prometheus-proxy:4.7.0 ``` -------------------------------- ### Start the proxy with java -jar prometheus-proxy.jar Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt Runs the proxy outside the firewall alongside Prometheus. Use this command to launch the proxy service. ```bash # Start the proxy (runs outside the firewall alongside Prometheus): java -jar prometheus-proxy.jar ``` -------------------------------- ### systemctl commands for prometheus-proxy service Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/production.md Run after installing the unit and creating the user. Enables and starts the service, checks status, follows logs, restarts to pick up config changes, and disables/stops. For an agent, use prometheus-agent.service instead. ```bash sudo systemctl daemon-reload sudo systemctl enable --now prometheus-proxy # start now and at every boot systemctl status prometheus-proxy # check that it is running journalctl -u prometheus-proxy -f # follow its log sudo systemctl restart prometheus-proxy # pick up an edited config sudo systemctl disable --now prometheus-proxy # stop, and no longer start at boot ``` -------------------------------- ### Install and run via Homebrew Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Installs the proxy and agent via Homebrew on macOS and Linux. Each formula installs the Java it runs on (openjdk@25), so there is no JAR to download. ```bash # On the proxy's machine, outside the firewall brew install pambrose/tap/prometheus-proxy prometheus-proxy # On the agent's machine, inside the firewall brew install pambrose/tap/prometheus-agent prometheus-agent --proxy mymachine.local \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### Start proxy and agent via CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/index.md Commands to run the proxy and agent as Java JARs. The agent connects to the proxy host and loads its configuration from a URL. ```bash # Start the proxy java -jar prometheus-proxy.jar # Start the agent java -jar prometheus-agent.jar \ --proxy proxy-host.example.com \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### Enable service discovery via environment variables Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/ServiceDiscoveryExamples.txt Environment variables to enable service discovery with path and target prefix. ```bash SD_ENABLED=true SD_PATH=discovery SD_TARGET_PREFIX=proxy-host.example.com:8080 ``` -------------------------------- ### Run demo: reset Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/nginx/README.md Resets nginx and the proxy to the state make up starts them. ```bash ./demo.sh reset # nginx and the proxy as make up starts them ``` -------------------------------- ### Install proxy and agent with Helm charts Source: https://github.com/pambrose/prometheus-proxy/blob/master/RELEASE_NOTES.md Installs the proxy and agent via Helm from the charts in charts/. The proxy is installed in the monitoring cluster next to Prometheus, and the agent in each target cluster with proxy.hostname and the agent's config in agent-values.yaml. Charts run as non-root with read-only root filesystem and wire health probes. ```bash # In the monitoring cluster, next to Prometheus helm install prometheus-proxy ./charts/prometheus-proxy --namespace monitoring --create-namespace \ --set agentService.enabled=true # In each target cluster, with proxy.hostname and the agent's config in agent-values.yaml helm install prometheus-agent ./charts/prometheus-agent -f agent-values.yaml ``` -------------------------------- ### Run agent in background with brew services Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Runs the agent as a service that starts at login. Copy your agent.conf to the service config path first. The service passes no --proxy, so the file's agent.proxy.hostname decides the proxy. Use brew services commands to manage it. ```bash cp agent.conf "$(brew --prefix)/etc/prometheus-agent.conf" brew services start prometheus-agent # start now and at every login brew services info prometheus-agent # check that it is running brew services restart prometheus-agent # pick up an edited config brew services stop prometheus-agent # stop, and no longer start at login ``` -------------------------------- ### Clone and build fat JARs with gradlew agentJar proxyJar Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt Builds the proxy and agent JARs from source. The generated JARs are placed in build/libs/ as prometheus-proxy.jar and prometheus-agent.jar. ```bash # Clone and build the fat JARs: git clone https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy ./gradlew agentJar proxyJar # JARs are generated in build/libs/: # build/libs/prometheus-proxy.jar # build/libs/prometheus-agent.jar ``` -------------------------------- ### Manage proxy and agent containers with docker commands Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/DockerExamples.txt Shows common Docker commands to check, follow logs, restart, stop, and remove the proxy and agent containers. Useful for operational tasks after starting the containers. ```bash docker ps --filter name=prometheus- # check that they are running docker logs --follow prometheus-proxy # follow a container's log docker restart prometheus-agent # restart it, e.g. to pick up an edited agent.conf docker stop prometheus-agent # stop it; it stays stopped when Docker restarts docker rm prometheus-agent # remove the stopped container ``` -------------------------------- ### Manage proxy background service with brew services Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Runs the proxy as a background service using the config at $(brew --prefix)/etc/prometheus-proxy.conf. Starts at login and restarts on failure. Edit config before starting to set ports and agent authentication. ```bash brew services start prometheus-proxy # start now and at every login brew services info prometheus-proxy # check that it is running brew services restart prometheus-proxy # pick up an edited config brew services stop prometheus-proxy # stop, and no longer start at login ``` -------------------------------- ### Enable service discovery via CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/ServiceDiscoveryExamples.txt Command-line flags to enable service discovery with a discovery path and target prefix. ```bash java -jar prometheus-proxy.jar \ --sd_enabled \ --sd_path discovery \ --sd_target_prefix proxy-host.example.com:8080 ``` -------------------------------- ### Follow Homebrew service log Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Tails the proxy log file at $(brew --prefix)/var/log/prometheus-proxy.log. ```bash tail -f "$(brew --prefix)/var/log/prometheus-proxy.log" ``` -------------------------------- ### Debugging local run with prom-agent.conf Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/examples.md Self-monitoring setup for troubleshooting with debug servlet enabled on admin port and labels dropped for readable output. Two toggles are commented out: transportFilterDisabled for nginx reverse proxy and scrapeTimeoutSecs for endpoints slower than 15 seconds. This config backs the bundled 'Agent (no auth)' IntelliJ run configuration. ```hocon proxy { admin.debugEnabled = true admin.enabled: true metrics.enabled: true #transportFilterDisabled = true http.requestLoggingEnabled: true } agent { //scrapeTimeoutSecs = 16 proxy.hostname = localhost admin.enabled: true metrics.enabled: true #transportFilterDisabled = true pathConfigs: [ { name: "Proxy metrics" path: proxy_metrics url: "http://localhost:8082/metrics" } { name: "Agent metrics" path: agent_metrics url: "http://localhost:8083/metrics" } ] } ``` -------------------------------- ### Enable dashboard via command line Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/web-dashboard.md Start the proxy with dashboard enabled on port 8094 using command-line flags. ```bash java -jar prometheus-proxy.jar --dashboard --dashboard_port 8094 ``` -------------------------------- ### Install proxy and agent via Helm Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/index.md Helm commands to install the proxy and agent charts. The proxy is installed with a LoadBalancer for agents in other clusters; the agent is configured with the proxy hostname and a config file. ```bash # From a clone of https://github.com/pambrose/prometheus-proxy # Start the proxy, in the cluster where Prometheus runs, with a LoadBalancer for agents in other clusters helm install prometheus-proxy ./charts/prometheus-proxy --namespace monitoring --create-namespace \ --set agentService.enabled=true # Start the agent, in the cluster whose services it scrapes helm install prometheus-agent ./charts/prometheus-agent \ --set proxy.hostname=proxy-host.example.com:50051 \ --set-file config=examples/myapps.conf ``` -------------------------------- ### Run agent with proxy via command line Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/configuration/agent.md Starts the agent with the proxy hostname and port specified on the command line, along with a configuration file. ```bash java -jar prometheus-agent.jar --proxy proxy-host.example.com:50051 --config agent.conf ``` -------------------------------- ### Run proxy in background with nohup Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Starts the proxy in the background, logging to proxy.log and saving the process ID. Follow the log and stop with kill. No automatic restart on exit or reboot. ```bash nohup java -jar prometheus-proxy.jar > proxy.log 2>&1 & echo $! > proxy.pid tail -f proxy.log # follow its log kill "$(cat proxy.pid)" # stop it ``` -------------------------------- ### Agent.startSyncAgent(args, exitOnMissingConfig) Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/embedded-agent.md Starts an agent from command-line arguments, as the standalone agent's main() does, and returns once the agent is running. Returns no handle; the agent runs on its own non-daemon thread. ```APIDOC ## Agent.startSyncAgent(args, exitOnMissingConfig) ### Description Starts an agent from command-line arguments, as the standalone agent's main() does, and returns once the agent is running. Returns no handle; the agent runs on its own non-daemon thread. ### Method startSyncAgent ### Parameters - **args** (Array) - Required - The agent's CLI options, such as `--config agent.conf` - **exitOnMissingConfig** (Boolean) - Required - `true` behaves as the standalone agent does, exiting the JVM on a config error. `false` throws `ConfigLoadException` instead, and with no `--config` falls back to the built-in defaults ### Throws - **ConfigLoadException** - When `exitOnMissingConfig` is `false`, in the cases `startAsyncAgent()` lists, and for `-v` or `-u` - **IllegalStateException** - When the agent fails to start, with the failure as its cause ### Returns - **Unit** - No return value ``` -------------------------------- ### Manage Homebrew services Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Starts, restarts, and stops the proxy and agent as background services. brew services also starts them at every login. Config files are in $(brew --prefix)/etc/. ```bash brew services start prometheus-proxy # start now and at every login brew services start prometheus-agent brew services restart prometheus-agent # pick up an edited config brew services stop prometheus-agent # stop, and no longer start at login ``` -------------------------------- ### Enable dashboard via environment variables Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/web-dashboard.md Start the proxy with dashboard enabled on port 8094 using environment variables. ```bash DASHBOARD_ENABLED=true DASHBOARD_PORT=8094 java -jar prometheus-proxy.jar ``` -------------------------------- ### Start the agent with -Dagent.proxy.hostname option Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Runs the agent inside the firewall with your services. Uses the -Dagent.proxy.hostname option to specify the proxy hostname. Runs in the foreground until Ctrl+C. ```bash java -jar prometheus-agent.jar \ -Dagent.proxy.hostname=mymachine.local \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### Service discovery JSON response Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/ServiceDiscoveryExamples.txt Example JSON response from the service discovery endpoint, listing targets and labels. ```json [ { "targets": ["proxy-host.example.com:8080"], "labels": { "__metrics_path__": "/app1_metrics", "agentName": "agent-01", "hostName": "internal.host.com", "env": "production", "team": "backend" } }, { "targets": ["proxy-host.example.com:8080"], "labels": { "__metrics_path__": "/app2_metrics", "agentName": "agent-01", "hostName": "internal.host.com", "env": "staging", "team": "backend" } } ] ``` -------------------------------- ### Install via Helm charts Source: https://github.com/pambrose/prometheus-proxy/blob/master/llms.txt Install the proxy and agent Helm charts from a clone of the repository. The proxy chart's agentService.enabled adds a LoadBalancer for agents in other clusters. The agent chart uses proxy.hostname and pathConfigs from agent-values.yaml. Since 4.4.0, secrets can come from a Secret via existingSecret instead of the ConfigMap. ```bash # Monitoring cluster, next to Prometheus (agentService adds a LoadBalancer for agents in other clusters) helm install prometheus-proxy ./charts/prometheus-proxy -n monitoring --create-namespace --set agentService.enabled=true # Each target cluster: proxy.hostname and the agent's pathConfigs (config, HOCON) in agent-values.yaml helm install prometheus-agent ./charts/prometheus-agent -f agent-values.yaml ``` -------------------------------- ### Clone and run the Nginx demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/nginx-demo.md Clone the repository at release 4.7.0 and run the demo from its directory. The first `make up` pulls images and takes a few minutes; subsequent starts are quick and work offline. Use `make tour` to walk through scenarios and `make down` to stop. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/nginx make up # pulls the images, starts everything, prints the URLs make tour # walks through every scenario below, pausing before each step make down # stops it and removes its containers and network ``` -------------------------------- ### Start the agent with --proxy shorthand flag Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt Alternative to the -Dagent.proxy.hostname flag. Uses the --proxy shorthand to specify the proxy hostname. ```bash # Or use the --proxy shorthand: java -jar prometheus-agent.jar \ --proxy proxy-host.example.com \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### Start the proxy Source: https://github.com/pambrose/prometheus-proxy/blob/master/README.md Runs the proxy outside the firewall with Prometheus. Requires Java 17 or newer. Runs in the foreground until Ctrl+C. ```bash java -jar prometheus-proxy.jar ``` -------------------------------- ### Clone and run the Spring Boot demo with make commands Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/spring-boot-demo.md Clone the repository at release 4.7.0 and run the demo from its directory. The first 'make up' pulls images and builds the roastery, taking a few minutes; subsequent starts take under a minute. 'make down' stops it and removes containers and network. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/spring-boot make up # builds the roastery, starts everything, prints the URLs make tour # walks through the parts below, pausing before each step make down # stops it and removes its containers and network ``` -------------------------------- ### Start the agent with java -jar prometheus-agent.jar and -Dagent.proxy.hostname Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt Runs the agent inside the firewall with your services. Requires the proxy hostname and a configuration file URL. ```bash # Start the agent (runs inside the firewall with your services): java -jar prometheus-agent.jar \ -Dagent.proxy.hostname=proxy-host.example.com \ --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf ``` -------------------------------- ### EmbeddedAgentConfig.start(logBanner) Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/embedded-agent.md Starts the agent asynchronously, similar to startAsyncAgent(config). Throws as startAsyncAgent does. logBanner defaults to true. ```APIDOC ## EmbeddedAgentConfig.start(logBanner) ### Description Starts the agent asynchronously, similar to startAsyncAgent(config). Throws as startAsyncAgent does. logBanner defaults to true. ### Method start ### Parameters - **logBanner** (Boolean) - Optional - Defaults to true ### Returns - **EmbeddedAgentInfo** - The handle for the started agent ``` -------------------------------- ### Kotlin test: failed startup should stop what the proxy started Source: https://github.com/pambrose/prometheus-proxy/blob/master/docs/superpowers/plans/2026-09-26-incidental-fixes.md Verifies that when a proxy startup fails (e.g., HTTP port bind failure), the admin and metrics servers started by super.startUp() are stopped and the proxy state becomes FAILED. The test captures values before assertSoftly so each check reports independently. The in-process gRPC server starts first, so the HTTP bind failure also exercises stopping an already-started sub-service. ```kotlin // ==================== Failed startup ==================== // Guava calls shutDown() only after startUp() succeeds. When a sub-service failed to start, the admin and metrics // servers super.startUp() had started and the sub-services already running were left up: a standalone proxy with // a taken port logged the failure but never exited, its admin server's threads keeping the JVM alive. "a failed startup should stop what the proxy started" { PrometheusRegistry.defaultRegistry.clear() val adminPort = ServerSocket(0).use { it.localPort } val metricsPort = ServerSocket(0).use { it.localPort } ServerSocket(0).use { takenHttpPort -> val proxy = Proxy( options = ProxyOptions( listOf( "--port", "${takenHttpPort.localPort}", "--admin", "--admin_port", "$adminPort", "--metrics", "--metrics_port", "$metricsPort", ), ), inProcessServerName = "failed-start-${System.nanoTime()}", testMode = true, ) shouldThrow { proxy.startSync() } // Captured as values first, so each check reports on its own inside assertSoftly. val state = proxy.state() val adminPortFree = runCatching { ServerSocket(adminPort).close() }.isSuccess val metricsRunning = proxy.metricsService.isRunning assertSoftly { state shouldBe Service.State.FAILED adminPortFree.shouldBeTrue() metricsRunning.shouldBeFalse() } } } ``` -------------------------------- ### Verify metrics with curl on /app1_metrics Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt Checks that metrics are flowing through the proxy by curling the app1_metrics endpoint on port 8080. ```bash # Verify metrics are flowing through the proxy: curl -s http://proxy-host.example.com:8080/app1_metrics | head ``` -------------------------------- ### Clone and run the basics demo Source: https://github.com/pambrose/prometheus-proxy/blob/master/llms.txt Clone the latest release tag and start the basics demo with make up. Requires Docker with Compose v2, git, make, and curl on macOS or Linux. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/basics make up ``` -------------------------------- ### Clone and run the network demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/network/README.md Clone the repository at release 4.7.0 and run the demo from its directory. The first make up pulls the proxy, agent, Prometheus, Grafana, Zipkin, Toxiproxy, and Python images, which takes a few minutes; afterwards it starts in under a minute. make down stops it and removes its containers and network. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/network make up # pulls the images, starts everything, and prints the URLs make tour # walks through the guided tour below, pausing before each step make down # stops it and removes its containers and network ``` -------------------------------- ### Agent with mutual TLS - CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/TlsExamples.txt Starts the agent with mutual TLS, providing a client certificate and trusting the CA. ```bash java -jar prometheus-agent.jar \ --config myconfig.conf \ --cert /path/to/client.crt \ --key /path/to/client.key \ --trust /path/to/ca.crt ``` -------------------------------- ### Verify service discovery with curl on /discovery Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/GettingStarted.txt If service discovery is enabled, this command lists registered targets using jq for pretty-printing. ```bash # If service discovery is enabled, check registered targets: curl -s http://proxy-host.example.com:8080/discovery | jq '.' ``` -------------------------------- ### Restart the proxy Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/basics/README.md Runs the demo script to start the proxy again. Agent-east reconnects and registers its paths within a few seconds. ```bash ./demo.sh proxy-up # starts it again ``` -------------------------------- ### Proxy with mutual TLS - CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/TlsExamples.txt Starts the proxy with mutual TLS, requiring clients to present a certificate trusted by the specified CA. ```bash java -jar prometheus-proxy.jar \ --cert /path/to/server.crt \ --key /path/to/server.key \ --trust /path/to/ca.crt ``` -------------------------------- ### Clone and run the embedded demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/embedded/README.md Clone the repository at release 4.7.0 and run the demo from its directory. The first make up pulls images and builds the coffee shop, taking a few minutes; subsequent starts take under a minute. make down stops the demo and removes containers and network. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/embedded make up # builds the coffee shop, starts everything, and prints the URLs make tour # walks through the guided tour below, pausing before each step make down # stops it and removes its containers and network ``` -------------------------------- ### Agent with TLS (no mutual authentication) - CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/TlsExamples.txt Starts the agent with TLS enabled, trusting a CA certificate. No client certificate is required. ```bash java -jar prometheus-agent.jar \ --config myconfig.conf \ --trust /path/to/ca.crt ``` -------------------------------- ### Clone and run the nginx demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/demos/nginx/README.md Clone the repository at release 4.7.0 and run the demo's make targets from its directory. The first make up pulls images and takes a few minutes; subsequent starts are under a minute. Ports can be overridden with environment variables like NGINX_DEMO_PROMETHEUS_PORT. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/nginx make up # pulls the images, starts everything, and prints the URLs make tour # walks through the guided tour below, pausing before each step make down # stops it and removes its containers and network ``` -------------------------------- ### Proxy with TLS (no mutual authentication) - CLI Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/TlsExamples.txt Starts the proxy with TLS enabled using a server certificate and key. No client certificate is required. ```bash java -jar prometheus-proxy.jar \ --cert /path/to/server.crt \ --key /path/to/server.key ``` -------------------------------- ### Follow Homebrew service log Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Follows the agent's log file when running as a Homebrew service. The log is at $(brew --prefix)/var/log/prometheus-agent.log. ```bash tail -f "$(brew --prefix)/var/log/prometheus-agent.log" ``` -------------------------------- ### Install PrometheusProxyAgent in Ktor application module Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/ktor-plugin.md Installs the plugin with a PrometheusMeterRegistry and a scrape path, and configures the embedded agent with name, proxy, and token from environment variables. The agent starts and stops with the app, serves metrics in-process at the proxy's /my_app_metrics, and stays off without a proxy unless required=true is set. ```kotlin fun Application.module() { // Ktor's HTTP metrics and the JVM's, then the app's own, in one registry val meterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT) install(MicrometerMetrics) { registry = meterRegistry } install(PrometheusProxyAgent) { // Served in-process, at the proxy's /my_app_metrics registry = meterRegistry.prometheusRegistry path = "my_app_metrics" agent { name = "my-app" // Unset, as on a developer's machine, the agent stays off proxy = System.getenv("PROMETHEUS_PROXY").orEmpty() token = System.getenv("PROMETHEUS_AGENT_TOKEN").orEmpty() } } routing { agentHealth() } } ``` -------------------------------- ### Build, lint, and run unit tests Source: https://github.com/pambrose/prometheus-proxy/blob/master/docs/superpowers/plans/2026-09-25-prometheus-client-1x-migration.md Step 13: Run detekt, lintKotlinMain, lintKotlinTest, build (excluding tests), then the full test suite. Expected: all green, including the new UtilsTest and start-time specs. ```bash ./gradlew detekt && ./gradlew lintKotlinMain lintKotlinTest && ./gradlew build -x test ./gradlew test ``` -------------------------------- ### Full agent configuration example Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/configuration/agent.md Real-world config from the examples/ directory. The proxy and agent monitor themselves: the agent serves the proxy's and its own metrics through the proxy at /proxy_metrics and /agent_metrics. On one host, run both with --config examples/simple.conf; in Docker, set PROXY_HOSTNAME to the proxy container's name. ```hocon // The proxy and the agent monitor themselves: the agent serves the proxy's and its own metrics through the proxy, at // /proxy_metrics and /agent_metrics. // // On one host, run both with --config examples/simple.conf. In Docker, an agent's localhost is its own container, so // the Docker quick start puts the two containers on one network and gives the agent PROXY_HOSTNAME, the proxy // container's name: the agent connects to the proxy there, and fetches the proxy's metrics from there too. // The proxy's host for its metrics: PROXY_HOSTNAME when it's set, so a host name without a port, and localhost // otherwise. The agent's own metrics are on its localhost wherever it runs. proxyMetricsHost = localhost proxyMetricsHost = ${?PROXY_HOSTNAME} proxy { admin.debugEnabled = false admin.enabled: true metrics.enabled: true http.requestLoggingEnabled: true } agent { proxy.hostname = localhost admin.enabled: true metrics.enabled: true pathConfigs: [ { name: "Proxy metrics" path: proxy_metrics labels: "{\"key1\": \"value1\", \"key2\": \"2\"}" url: "http://"${proxyMetricsHost}":8082/metrics" } { name: "Agent metrics" path: agent_metrics labels: "{\"key3\": \"value3\", \"key4\": \"4\"}" url: "http://localhost:8083/metrics" } ] } ``` -------------------------------- ### Dockerfile for embedded agent app Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/EmbeddedAgentExamples.txt Multi-stage Dockerfile that builds the app with Gradle and runs it on a JRE as a non-root user. Sets JAVA_OPTS for Netty and heap sizing, exposes port 8080, and starts the app. ```dockerfile # Build the app with its own Gradle wrapper, on a JDK, keeping Gradle's downloads between builds FROM eclipse-temurin:25-jdk-noble AS build WORKDIR /src COPY . . RUN --mount=type=cache,target=/root/.gradle ./gradlew --no-daemon installDist # Run it on a JRE, as a user that isn't root, named by number FROM eclipse-temurin:25-jre-noble RUN useradd --system --uid 1001 --home-dir /app app COPY --from=build /src/build/install/my-app /app USER 1001 # Lets Netty, which the agent's gRPC runs on, load its native TLS library and use sun.misc.Unsafe on Java 24 and later, # and sizes the heap from the container's memory ENV JAVA_OPTS="-XX:MaxRAMPercentage=75 --enable-native-access=ALL-UNNAMED --sun-misc-unsafe-memory-access=allow" # The app's own port; the agent opens none, since it connects out to the proxy EXPOSE 8080 ENTRYPOINT ["/app/bin/my-app"] ``` -------------------------------- ### Run proxy and agent in background with local config Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/DockerExamples.txt Starts both containers detached with --restart unless-stopped. The agent mounts a local agent.conf file and uses PROXY_HOSTNAME to point to the proxy host. ```bash # Run the proxy in the background: docker run --detach --name prometheus-proxy --restart unless-stopped \ -p 8080:8080 -p 50051:50051 \ pambrose/prometheus-proxy:4.7.0 # Run an agent in the background with a local config file: docker run --detach --name prometheus-agent --restart unless-stopped \ --mount type=bind,source="$(pwd)"/agent.conf,target=/app/agent.conf \ --env AGENT_CONFIG=agent.conf \ --env PROXY_HOSTNAME=proxy-host.example.com \ pambrose/prometheus-agent:4.7.0 ``` -------------------------------- ### Dynamic discovery targets file (discovery-targets.conf) Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/examples.md Standalone targets file for dynamic target discovery, not passed to --config. Has a top-level paths list and no agent wrapper. The agent re-reads it every reconcileIntervalSecs and registers, unregisters, or re-registers paths to match; static pathConfigs entries are a baseline that reconciliation never touches, and collisions are logged with the static entry winning. Only path and url are required; name defaults to path, labels defaults to "{}", and blank path or url entries are skipped. Labels is a JSON string, not a nested object; HOCON triple quotes avoid backslash escaping. Path must be a single segment; multi-segment values are rejected. Substitutions are resolved, and ${?VAR} is optional. An empty-but-valid file (paths = []) is honored, but an unreadable file is treated as a failed read, logging a warning and keeping the last-known-good set. ```hocon // Dynamic target discovery file, referenced by agent.discovery.file.path. // // This is a standalone targets file, NOT an agent config -- there is no `agent { }` wrapper here. // Point an agent at it from that agent's own config: // // agent { // discovery { // enabled = true // file.path = "examples/discovery-targets.conf" // reconcileIntervalSecs = 30 // } // } // // The agent re-reads this file every reconcileIntervalSecs and registers, unregisters, or // re-registers paths so the live set matches it -- no restart, and paths that did not change keep // scraping. Static agent.pathConfigs entries are a baseline reconciliation never touches; if a path // here collides with a static one, the static entry wins and the collision is logged. // // JSON is equally valid, since HOCON is a JSON superset -- convenient if this file is generated. paths = [ // Only `path` and `url` are required: `name` defaults to `path`, `labels` defaults to "{}". An entry whose // `path` or `url` is blank is skipped when this file is read, reported once, and the rest of the file applies. { path = "app1_metrics", url = "http://app1.local:9100/metrics" } // Full form. `labels` is a JSON *string*, not a nested object; HOCON triple quotes avoid the // backslash escaping used in the pathConfigs examples. { name = "App2 metrics" path = "app2_metrics" url = "http://app2.local:9100/metrics" labels = """{"env": "prod", "team": "platform"}""" } ] // `path` must be a single segment: the proxy serves each registered path at /, so a // multi-segment value like "app/metrics" is rejected at registration. Use "app_metrics". // Substitutions are resolved, so a generated or environment-driven file can avoid repetition. // The ${?VAR} form is optional: it overrides the preceding value when set and falls back to it // when unset. Uncomment to try: // // host = "app3.local" // port = 9100 // port = ${?METRICS_PORT} // // paths = [ // { path = "app3_metrics", url = "http://"${host}":"${port}"/metrics" } // ] // Removing every discovered path is spelled `paths = []` -- an empty-but-valid file is a real // instruction and is honored. Deleting or corrupting this file is NOT: an unreadable file is // treated as a failed read, so the agent logs a warning, skips the tick, and keeps its // last-known-good set rather than tearing every target down on a bad write, re-registering it if // the agent reconnects to the proxy meanwhile. ``` -------------------------------- ### Load configuration from local file Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/configuration/index.md Commands to start the agent and proxy with a local configuration file using the --config option. ```bash java -jar prometheus-agent.jar --config /etc/prometheus-proxy/agent.conf java -jar prometheus-proxy.jar --config /etc/prometheus-proxy/proxy.conf ``` -------------------------------- ### Run WAN down demo Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/network-demo.md Starts the demo where every link goes down. Both agents retry every 3 seconds, alternating between their two links, and the NetworkNoAgentsConnected alert fires after about 20 seconds. ```bash ./demo.sh wan-down # every link goes down ``` -------------------------------- ### Gradle dependency for Spring Boot starter Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/EmbeddedAgentExamples.txt Adds the prometheus-proxy-spring-boot-starter and actuator dependencies in build.gradle.kts with Spring Boot's dependency management. ```kotlin // build.gradle.kts, with Spring Boot's dependency management (the io.spring.dependency-management plugin) dependencies { implementation("com.pambrose:prometheus-proxy-spring-boot-starter:4.7.0") implementation("org.springframework.boot:spring-boot-starter-actuator") } ``` -------------------------------- ### Clone and run Kubernetes demo with make Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/kubernetes-demo.md Clone the prometheus-proxy repository at release 4.7.0 and run the demo's make targets from its directory. `make up` creates both clusters and installs everything, `make tour` walks through scenarios, and `make down` deletes the clusters. ```bash git clone -c advice.detachedHead=false --depth 1 --branch 4.7.0 https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy/demos/kubernetes make up # creates both clusters, installs everything, prints the URLs make tour # walks through every scenario below, pausing before each step make down # deletes both clusters ``` -------------------------------- ### Run Agent with TLS (no mutual auth) Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/DockerExamples.txt Starts the prometheus-agent container with TLS enabled via mounted certs and tls.conf. Requires certs directory and tls.conf file in the current working directory. Connects to the proxy at proxy-host:50440. ```bash docker run --rm \ -p 8083:8083 \ -p 8093:8093 \ --mount type=bind,source="$(pwd)"/certs,target=/app/certs \ --mount type=bind,source="$(pwd)"/tls.conf,target=/app/tls.conf \ --env AGENT_CONFIG=tls.conf \ --env PROXY_HOSTNAME=proxy-host:50440 \ pambrose/prometheus-agent:4.7.0 ``` -------------------------------- ### Lint and review (Step 5) Source: https://github.com/pambrose/prometheus-proxy/blob/master/docs/superpowers/plans/2026-09-25-prometheus-client-1x-migration.md Commands to run linting and build checks, and to show the diff stat. Includes `detekt`, `lintKotlinMain`, `lintKotlinTest`, and `build -x test`. ```bash ./gradlew detekt && ./gradlew lintKotlinMain lintKotlinTest && ./gradlew build -x test git diff --stat ``` -------------------------------- ### Enable service discovery via config file Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/ServiceDiscoveryExamples.txt HOCON configuration block to enable service discovery with path and target prefix. ```hocon proxy { service.discovery { enabled = true path = "discovery" targetPrefix = "proxy-host.example.com:8080" } } ``` -------------------------------- ### Build from Source: Clone and Build JARs Source: https://github.com/pambrose/prometheus-proxy/blob/master/website/prometheus-proxy/docs/getting-started.md Clone the repository and build the proxy and agent JARs with Gradle. The JARs are generated in build/libs/ as prometheus-proxy.jar and prometheus-agent.jar. ```bash git clone https://github.com/pambrose/prometheus-proxy.git cd prometheus-proxy ./gradlew agentJar proxyJar ``` -------------------------------- ### Bash: reproduce failed startup against the JAR Source: https://github.com/pambrose/prometheus-proxy/blob/master/docs/superpowers/plans/2026-09-26-incidental-fixes.md Builds the proxy JAR and runs two proxy instances to reproduce the failed-startup scenario. The first proxy holds the agent port (28151); the second attempts to bind the same agent port and an HTTP port (28181) with metrics on 28194. Expected: the second proxy logs BindException, exits non-zero within a few seconds, and port 28194 is free. Before the fix it was still running 15 s later with 28194 listening. Stop the first proxy afterwards. ```bash ./gradlew -q proxyJar java -jar build/libs/prometheus-proxy.jar -p 28180 -a 28151 & # holds the agent port java -jar build/libs/prometheus-proxy.jar -p 28181 -a 28151 -r -i 28194; echo "exit=$?" ``` -------------------------------- ### Run Agent trusting CA via environment variable Source: https://github.com/pambrose/prometheus-proxy/blob/master/src/test/kotlin/website/DockerExamples.txt Starts the prometheus-agent container trusting the CA that signed the proxy's certificate, provided as an environment variable. Requires agent.conf and ca.crt files in the current directory. Connects to the proxy at proxy-host:50051. ```bash docker run --rm \ --mount type=bind,source="$(pwd)"/agent.conf,target=/app/agent.conf \ --env AGENT_CONFIG=agent.conf \ --env PROXY_HOSTNAME=proxy-host:50051 \ --env TRUST_CERT_COLLECTION_PEM="$(cat ca.crt)" \ pambrose/prometheus-agent:4.7.0 ```