EmbeddedAgentConfig

An embedded agent's settings, built in code with typed methods rather than as a config file, and started with start. It suits an app that holds the agent's settings itself, such as a token, the proxy's certificate, or the credentials for its own /metrics: they're held in memory and never written to disk.

From Java, build one with builder; from Kotlin, with embeddedAgent:

val agent =
embeddedAgent {
name = "my-app-$version"
proxy = "proxy.example.com:50051"
token = agentToken
trustCertificatePem(pem = certificatePem, authority = "prometheus-proxy")
scrapeSelf(path = "my_app_metrics", port = 8080, username = user, password = password)
}.start(logBanner = false)

It builds the same tree a config file holds, rooted at agent, so starting it behaves as Agent.startAsyncAgent does with a Config: the built-in defaults fill in what isn't set, the environment variables of single settings take precedence, and a setting the agent can't use throws ConfigLoadException. toConfig gives the tree itself.

Types

Link copied to clipboard
class Builder

Builds an EmbeddedAgentConfig. Each method returns the builder, so calls chain in Java and read as statements in Kotlin's embeddedAgent block; a method called twice keeps its last value, and path and scrapeSelf add a path each time. Anything the builder has no method for, setting sets by its key. A value the builder can tell is wrong, such as a port out of range, throws ConfigLoadException, as start does for one the agent rejects.

Link copied to clipboard
object Companion

Where an EmbeddedAgentConfig starts.

Functions

Link copied to clipboard

Starts an agent with these settings, as Agent.startAsyncAgent does with a Config, and returns its handle once it has started.

Link copied to clipboard
fun toConfig(): Config

The settings as the Config tree a config file would hold, rooted at agent.

Link copied to clipboard
open override fun toString(): String

The settings, setting's included, with the token, a password, and each PEM shown only as set or not, and the credentials in a path's URL masked, so an app can log it.