AWS Auto Scaling & Elastic Beanstalk
Auto Scaling groups and Elastic Beanstalk environments create and replace instances automatically. The usual install flow assumes a stable host. You install the agent, then choose which apps to instrument in the KloudMate UI. That does not work when instances come and go. There is no lasting host to configure, and a setting made on one instance is not carried to the next.
You can give each new instance its APM settings in two ways, both with no UI step:
| Host policy | Autonomous mode | |
|---|---|---|
| What’s traced | The applications your rules pick, in the mode you choose | Every application the agent finds, with the SDK where it can |
| The agent in KloudMate | Registered like any other agent: pipeline rules, configuration changes, and upgrades keep working | Doesn’t check in, so it takes no configuration from the UI |
| Agent version | 2.12 or later | Any |
Use a host policy unless you want everything traced and don’t need to manage the agents from KloudMate. You provide either one through the platform’s provisioning step: user-data for an Auto Scaling group, the AMI itself, or a .platform hook for Elastic Beanstalk. An Elastic Beanstalk environment runs on an Auto Scaling group underneath, so the agent configuration is the same for both.
Set APM with a host policy
Section titled “Set APM with a host policy”A host policy is a file, /etc/kmagent/apm.yaml, with rules that pick applications by name, runtime, or unit. Every instance reads it when the agent starts, applies it to the applications it finds, and reports to KloudMate as a normal agent. In Settings → Agents & Pipelines, each instance’s row shows APM from host policy.
Before you write the rules, run sudo kmagent apm check on an instance that runs your applications. It prints the name, unit, and ports to match on. See Find the values to match on.
In the launch template
Section titled “In the launch template”Write the policy before you install the agent, so the agent reads it on its first start:
Each application set to sdk restarts once on the instance’s first boot, when the agent adds the SDK.
In an AMI
Section titled “In an AMI”To create instances that start with the SDK already set up, with no restart, set it up on one instance and image it:
- On the source instance, install the agent and write
/etc/kmagent/apm.yaml. Restart the agent withsudo systemctl restart kmagent. - Run
sudo kmagent apm check. Each application you picked should showmode sdkormode ebpf, and its traces should arrive in KloudMate. - Check that
/etc/kmagent/agent.yamlhas nohost-name. KloudMate tells instances apart by host name, so a fixed name makes every instance report as the same agent. - Create the AMI.
On an instance launched from the AMI, an application run by a systemd unit starts with the SDK, because the unit’s drop-in is part of the image. The agent finds the same settings in the policy and leaves the application running. A JVM started from /etc/rc.local, cron, or a script gets the SDK attached after it starts, with no restart. The instance registers as a new agent. It doesn’t take the source instance’s UI selection, which belongs to the source instance’s agent.
On Elastic Beanstalk
Section titled “On Elastic Beanstalk”Use the predeploy hook below, with two changes: write /etc/kmagent/apm.yaml before the install step, and remove export KM_AUTO_INSTRUMENT=true. On later deploys, the hook restarts the agent, which reads the policy again.
Change the rules
Section titled “Change the rules”The agent reads the policy only when it starts. To change it across a fleet, update the launch template or the AMI and replace the instances, or edit /etc/kmagent/apm.yaml and restart the agent on each instance, for example with AWS Systems Manager Run Command. A change you save in the UI applies only to the instance you made it on.
Autonomous mode
Section titled “Autonomous mode”Autonomous auto-instrument mode removes the per-instance UI step by instrumenting everything. The agent discovers and instruments every application on the instance itself and doesn’t check in with KloudMate for configuration. Your API key identifies the telemetry, so a new instance starts reporting as soon as it boots.
What autonomous mode collects
Section titled “What autonomous mode collects”With auto-instrument turned on, every instance gets the following, with no UI step:
- eBPF monitoring. HTTP server spans, RED metrics, and the service map for every app, whatever the language, with no code change. It’s also the only tracing method for runtimes with no SDK injection, such as Ruby and Go. See eBPF observability.
- SDK auto-instrumentation. Deeper, in-process traces for Java, .NET, Node.js, Python, and PHP. The agent injects the SDK through a systemd config file and restarts each app once to pick it up.
- Host metrics and logs. The metrics the agent always collects, plus any log files you configure below.
Each app’s service.name comes from its own stable identity, not from the instance. So every instance of one app rolls up as a single service in KloudMate, and a per-instance breakdown is still available. See Telemetry identity.
Before you start
Section titled “Before you start”You need:
- Your KloudMate API key.
- The collector endpoint,
https://otel.kloudmate.com:4318. - Instances on a supported Linux (Amazon Linux 2 or 2023, Ubuntu, Debian, the RHEL family, or SLES 15). eBPF monitoring needs a modern kernel, which the standard AWS AMIs have.
- Network access and permissions from Before you start if your outbound traffic is restricted.
The examples on this page put the API key directly into the provisioning step. To keep it out of the launch template, read it from SSM Parameter Store or Secrets Manager instead and set KM_API_KEY from there. That is the only line that changes.
Auto Scaling group
Section titled “Auto Scaling group”Put this in the launch template’s user-data. It writes the agent configuration, installs the agent with autonomous mode on, and starts it. Running the script again changes nothing, so it’s safe to run on every instance launch.
Elastic Beanstalk
Section titled “Elastic Beanstalk”Elastic Beanstalk runs a provisioning hook on each instance. On the current Amazon Linux 2 and 2023 platforms, use a platform hook. Your environment properties are available there.
1. Set the environment properties on the environment (Console → Configuration → Software → Environment properties, or eb setenv):
2. Add a predeploy hook to your application source bundle at .platform/hooks/predeploy/01-kmagent.sh, and make it executable with chmod +x:
Configure log collection
Section titled “Configure log collection”Autonomous mode has no UI, so the agent reads its log sources from files. At startup it reads every *.yaml or *.yml file in /etc/kmagent/logs.d/. (Point it at a different directory with KM_LOG_SOURCES_DIR.) Each file is a YAML list of sources. Add as many files as you need; they merge in filename order. An empty directory means no log collection, so it’s entirely opt-in.
Each source takes these fields:
| Field | Required | Notes |
|---|---|---|
name | Yes | Source name, also stamped on every record as km.log.source. |
include | Yes | List of file globs to tail. |
exclude | No | List of globs to skip. |
format | Yes | plaintext, json, or regex. |
parsing | For json and regex | Parsing rules: timestamp_field, timestamp_layout (iso8601, rfc3339, unix, unix_ms, or custom with custom_layout), severity_field, message_field, regex, multiline_pattern, encoding. |
attributes | No | Extra resource attributes. Set service.name to the app’s name so its logs join its traces. |
include_file_path | No | Add the source file’s path as an attribute. |
A JSON application log:
An nginx access log, parsed with a regex:
For the managed-mode version, with the same parsing choices in a UI wizard, see Log monitoring.
Name your services and tune eBPF
Section titled “Name your services and tune eBPF”eBPF names a service after the process it instruments. On the Beanstalk web tier that’s nginx — your app runs behind it on a unix socket — so Ruby, Go, and other eBPF-traced apps show up as nginx. Name and scope the service with two environment properties, written to the agent’s environment file in the hook:
KM_EBPF_OPEN_PORTS=80 scopes tracing to your app’s port, so background processes — the SSM agent, cfn-hup, the health app — stay out. KM_EBPF_SERVICE_NAME=checkout names the traces checkout. SDK runtimes (Java, Node.js, Python, .NET) read OTEL_SERVICE_NAME from the app process itself, so for those you set that property and nothing else.
| Environment property | Effect |
|---|---|
KM_EBPF_SERVICE_NAME | Name for the eBPF-traced service. Use with KM_EBPF_OPEN_PORTS. |
KM_EBPF_OPEN_PORTS | Ports eBPF instruments. Default: all listening ports. |
KM_EBPF_ENABLED | false turns off eBPF traces, keeps metrics and logs. |
KM_EBPF_NETWORK_ENABLED | false turns off the network topology map. |
KM_LOG_SOURCES_DIR | Log-source directory. Default: /etc/kmagent/logs.d. |
Verify
Section titled “Verify”On any instance:
With a host policy, the log shows APM policy loaded, and kmagent apm check shows the mode each application got. In autonomous mode, the log shows auto-instrument mode enabled. If you configured log collection, it also shows the log sources being merged. In KloudMate, the host appears with its cloud attributes, your services show traces and RED metrics, and log sources appear under their service.name.
If an instance isn’t reporting, check the agent’s own error logs. It ships them under service.name=kmagent. See See the agent’s own errors.
Notes and limits
Section titled “Notes and limits”- One restart on first boot. The agent restarts each app set to the SDK once to inject it. Autonomous mode does this for every app it can. That applies to the SDK languages, not to eBPF monitoring. To skip the restart at boot, bake the agent into your AMI so the instrumentation is already configured when the instance starts.
- Configuration is fixed per instance. In autonomous mode the agent doesn’t take configuration from the KloudMate UI. You change what’s instrumented, or your log sources, by updating the launch template or the
.platformhook and redeploying. The agent still reports its health to KloudMate. - Databases aren’t auto-instrumented. They need credentials, which can’t be configured automatically, so monitor RDS or a separate database tier through database monitoring.
- Log sources are read at startup. The agent reads
logs.donce, when it starts. Instances that are replaced rather than reconfigured don’t need it re-read.