startSyncAgent

fun startSyncAgent(args: Array<String>, exitOnMissingConfig: Boolean)(source)

Starts an Agent and returns once it is running.

Logs the agent banner and version, parses args into an AgentOptions, constructs an Agent, and calls startSync(), which waits up to 30 seconds for the Agent to start and throws if it doesn't. The Agent then runs on its own service thread, which isn't a daemon thread, so a JVM whose main() calls this keeps running until the Agent stops (e.g. a process signal, a fatal error, or stop).

Use this from main(), as the standalone Agent does. For embedded usage inside another running JVM, use startAsyncAgent, which returns an EmbeddedAgentInfo handle for stopping it.

Parameters

args

Raw command-line arguments forwarded to AgentOptions for parsing.

exitOnMissingConfig

When true, the Agent behaves as the standalone CLI does: it requires a config file or URL, and logs the reason and exits the process when the config can't be loaded, a setting is invalid (from the config, the command line, or an environment variable; see startAsyncAgent for what that covers), or -v/-u is given. When false, as when embedding, it falls back to the built-in reference config when none is given, and throws io.prometheus.common.ConfigLoadException in those cases instead.

Throws

when exitOnMissingConfig is false and the config can't be loaded, a setting is invalid, or -v/-u is given.

if the Agent fails to start, with the startup failure as the cause.