General-purpose KloudMate agent for VMs, bare metal, and Docker
The kmagent is a general-purpose OpenTelemetry collector agent designed for deployment on virtual machines, bare metal servers, and Docker containers. It provides service management capabilities and supports both file-based and remote configuration.
Path to the OpenTelemetry collector configuration file. This is the main collector config that defines receivers, processors, exporters, and pipelines.Environment Variable:KM_COLLECTOR_CONFIGDefault: Platform-specific (see below)Example:
OpenTelemetry exporter endpoint where telemetry data (traces, metrics, logs) is sent. Must be a valid HTTP/HTTPS URL.Environment Variable:KM_COLLECTOR_ENDPOINTExample:
API key for authentication with KloudMate services. Required for remote configuration updates and telemetry export.Environment Variable:KM_API_KEYExample:
kmagent start --api-key="km_xxxxxxxxxxxxx"
Store API keys securely. Never commit them to version control or expose them in logs. Use environment variables or secret management systems.
Interval in seconds to check for remote configuration updates. The agent polls the update endpoint at this interval.Environment Variable:KM_CONFIG_CHECK_INTERVALExample:
kmagent start --config-check-interval="120"
Set to 0 to disable automatic configuration updates. The agent will only use the local configuration file.
Auto-derived URL: If not specified, the update endpoint is automatically derived from the --collector-endpoint by extracting the root domain and prepending api.. For example:
func GetAgentConfigUpdaterURL(collectorEndpoint string) string { const fallbackURL = "https://api.kloudmate.com/agents/config-check" u, _ := url.Parse(collectorEndpoint) host := u.Hostname() parts := strings.Split(host, ".") if len(parts) < 2 { return fallbackURL } // Reconstruct the root domain from the last two parts. // e.g., "otel.kloudmate.dev" -> "kloudmate.dev" rootDomain := parts[len(parts)-2] + "." + parts[len(parts)-1] // Build the new URL using the robust url.URL struct updateURL := url.URL{ Scheme: u.Scheme, // Use the original scheme (e.g., "https") Host: "api." + rootDomain, // Prepend "api." to the new host Path: "/agents/config-check", // Set the static path } return updateURL.String()}
[Unit]Description=KloudMate Agent for OpenTelemetry auto instrumentationAfter=network.target[Service]Type=simpleUser=kmagentGroup=kmagentExecStart=/usr/local/bin/kmagent start --agent-config=/etc/kmagent/agent-config.yamlRestart=on-failureRestartSec=10[Install]WantedBy=multi-user.target
The agent implements graceful shutdown with proper cleanup:From cmd/kmagent/main.go:62-88:
func (p *Program) Stop(s service.Service) error { p.logger.Info("Stopping service...") // 1. Signal all dependent components to stop if p.cancelFunc != nil { p.logger.Info("Cancelling program context...") p.cancelFunc() } // 2. Shutdown the agent gracefully if p.kmAgent != nil { p.logger.Info("Shutting down KloudMate agent...") shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second) defer shutdownCancel() if err := p.kmAgent.Shutdown(shutdownCtx); err != nil { p.logger.Errorf("Error during agent shutdown: %v", err) } else { p.logger.Info("KloudMate agent shut down successfully.") } } // 3. Wait for the main program goroutine to finish p.logger.Info("Waiting for program run goroutine to complete...") p.wg.Wait() p.logger.Info("Service stopped successfully.") return nil}
Shutdown sequence:
Cancel context to signal all goroutines
Gracefully shutdown collector with 30-second timeout