Agent
Prometheus Agent that connects to a Proxy to enable metrics scraping across firewalls.
The Agent is the component that runs inside the firewall alongside the services being monitored. It establishes an outbound connection to the Proxy, registers the metrics endpoints it can scrape, and responds to scrape requests by fetching metrics from the actual endpoints and returning them to the Proxy.
Architecture
The Agent maintains a persistent gRPC connection to the Proxy and handles:
Connection Management: Establishes and maintains connection to proxy with automatic reconnection
Path Registration: Registers configured metrics endpoints with the proxy
Scrape Processing: Responds to scrape requests by fetching metrics from local endpoints
Concurrent Scraping: Handles multiple concurrent scrape requests with configurable limits
Heartbeat: Sends periodic heartbeat messages to maintain connection health
Metrics Collection: Exposes operational metrics about the agent itself
Configuration
Agents are configured via HOCON configuration files that specify:
Proxy connection details (hostname, port, TLS settings)
Path configurations (endpoints to scrape and their metadata)
Operational parameters (timeouts, concurrency limits, retry policies)
Admin and metrics endpoints for monitoring the agent itself
Usage Examples
Basic Usage
val agent = Agent(AgentOptions(args))
agent.startSync()Embedded Usage
val agentInfo = Agent.startAsyncAgent("config.conf", true)
println("Started agent: ${agentInfo.agentName}")With Custom Initialization
val agent = Agent(options) {
// Custom initialization logic
logger.info { "Agent initialized with custom settings" }
}
agent.startSync()Connection Lifecycle
Startup: Agent reads configuration and initializes services
Connection: Establishes gRPC connection to proxy
Registration: Registers configured paths with proxy
Operation: Processes scrape requests and sends heartbeats
Reconnection: Automatically reconnects on connection failures
Shutdown: Gracefully closes connections and cleans up resources
Error Handling
The Agent includes robust error handling for:
Network connectivity issues with exponential backoff
Individual scrape failures without affecting other scrapes
Configuration errors with detailed error messages
Resource exhaustion with proper cleanup
Since
1.0.0
Parameters
Configuration options for the agent, typically loaded from command line or config files
Optional in-process server name for testing scenarios. When specified, the agent will connect to an in-process gRPC server instead of a network server.
Whether to run in test mode. Test mode may disable certain features or use different defaults suitable for testing environments.
Optional initialization block executed after construction but before startup. Useful for custom configuration or testing setup.
See also
for configuration details
for the corresponding proxy component
for information about embedded agent instances
Constructors
Properties
Functions
Waits for the initial connection to the proxy to be established.
Atomically decrements scrapeRequestBacklogSize by delta, clamping at zero.
Marks the current time as when the last message was sent to the proxy.
Executes metrics operations if metrics collection is enabled.
Updates the scrape counter metrics for the specified operation type.