startAsyncAgent

fun startAsyncAgent(configFilename: String, exitOnMissingConfig: Boolean, logBanner: Boolean = true): EmbeddedAgentInfo(source)

Starts an Agent on a background thread and returns once it has started, suitable for embedding inside another JVM application.

Unlike startSyncAgent, this does not block for the Agent's lifetime. It waits only for startup -- the admin and metrics servers binding their ports -- and not for a proxy connection. The Agent's lifecycle is then owned by the caller via the returned EmbeddedAgentInfo, which exposes the agent's launchId and agentName and a shutdown() method for graceful shutdown.

Return

An EmbeddedAgentInfo handle for inspecting and shutting down the launched Agent.

Parameters

configFilename

Path or URL to the HOCON config file. Forwarded to the AgentOptions config-filename constructor so it follows the same resolution rules as the --config CLI flag.

exitOnMissingConfig

Pass false when embedding: a config that can't be loaded, an invalid option, or -v/-u then throws io.prometheus.common.ConfigLoadException for the host to catch. true gives the standalone CLI's behavior, which requires a config and exits the process on any of these, host and all.

logBanner

When true (default), logs the Agent ASCII banner and version on startup. Pass false to suppress banner output when embedding inside an app that owns its own logging surface.

Throws

if the Agent fails to start, for example because its admin or metrics port is already in use. The startup failure is the cause, and whatever the Agent had opened is released first.