|
| 1 | +[[otel-agent-transform]] |
| 2 | +== Transform an installed {agent} to run as an OTel Collector |
| 3 | + |
| 4 | +preview::[] |
| 5 | + |
| 6 | +If you have a currently installed standalone {agent}, it can be configured to run as an <<otel-agent,OTel Collector>>. This allows you to run {agent} both as a service and in an OTel Collector mode. |
| 7 | + |
| 8 | +In order to configure an installed standalone {agent} to run as an OTel Collector, it's enough to include a valid <<otel-agent,OTel Collector>> configuration in the `elastic-agent.yml` file, as shown in the following example. |
| 9 | + |
| 10 | +=== Example: configure {agent} to ingest host logs and metrics into Elasticsearch using the OTel Collector |
| 11 | + |
| 12 | +**Prerequisites** |
| 13 | + |
| 14 | +You'll need the following: |
| 15 | + |
| 16 | +. A suitable <<create-api-key-standalone-agent,{es} API key>> for authenticating on Elasticsearch |
| 17 | +. An installed standalone {agent} |
| 18 | +. A valid OTel Collector configuration. In this example we'll use the OTel sample configuration included in the {agent} repository: `otel_samples/platformlogs_hostmetrics.yml`. |
| 19 | +** link:https://github.com/elastic/elastic-agent/blob/main/internal/pkg/otel/samples/linux/platformlogs_hostmetrics.yml[Linux version] |
| 20 | +** link:https://github.com/elastic/elastic-agent/blob/main/internal/pkg/otel/samples/darwin/platformlogs_hostmetrics.yml[MacOS version] |
| 21 | + |
| 22 | +**Steps** |
| 23 | + |
| 24 | +To change a running standalone {agent} to run as an OTel Collector: |
| 25 | + |
| 26 | +. Create a directory where the OTel Collector can save its state. In this example we use `<{agent} install directory>/data/otelcol`. |
| 27 | +. Open the `<{agent} install directory>/otel_samples/platformlogs_hostmetrics.yml` file for editing. |
| 28 | +. Set environment details to be used by OTel Collector: |
| 29 | +* **Option 1:** Define environment variables for the {agent} service: |
| 30 | +** `ELASTIC_ENDPOINT`: The URL of the {es} instance where data will be sent |
| 31 | +** `ELASTIC_API_KEY`: The API Key to use to authenticate with {es} |
| 32 | +** `STORAGE_DIR`: The directory where the OTel Collector can persist its state |
| 33 | +* **Option 2:** Replace the environment variable references in the sample configuration with the corresponding values: |
| 34 | +** `${env:ELASTIC_ENDPOINT}`:The URL of the {es} instance where data will be sent |
| 35 | +** `${env:ELASTIC_API_KEY}`: The API Key to use to authenticate with {es} |
| 36 | +** `${env:STORAGE_DIR}`: The directory where the OTel Collector can persist its state |
| 37 | +. Save the opened OTel configuration as `elastic-agent.yml`, overwriting the default configuration of the installed agent. |
| 38 | +. Run the `elastic-agent status` command to verify that the new configuration has been correctly applied: |
| 39 | ++ |
| 40 | +[source,shell] |
| 41 | +---- |
| 42 | +elastic-agent status |
| 43 | +---- |
| 44 | +The OTel Collector running configuration should appear under `elastic-agent` key (note the `extensions` and `pipeline` keys): |
| 45 | ++ |
| 46 | +[source,shell] |
| 47 | +---- |
| 48 | +┌─ fleet |
| 49 | +│ └─ status: (STOPPED) Not enrolled into Fleet |
| 50 | +└─ elastic-agent |
| 51 | + ├─ status: (HEALTHY) Running |
| 52 | + ├─ extensions |
| 53 | + │ ├─ status: StatusOK |
| 54 | + │ └─ extension:file_storage |
| 55 | + │ └─ status: StatusOK |
| 56 | + ├─ pipeline:logs/platformlogs |
| 57 | + │ ├─ status: StatusOK |
| 58 | + │ ├─ exporter:elasticsearch/otel |
| 59 | + │ │ └─ status: StatusOK |
| 60 | + │ ├─ processor:resourcedetection |
| 61 | + │ │ └─ status: StatusOK |
| 62 | + │ └─ receiver:filelog/platformlogs |
| 63 | + │ └─ status: StatusOK |
| 64 | + └─ pipeline:metrics/hostmetrics |
| 65 | + ├─ status: StatusOK |
| 66 | + ├─ exporter:elasticsearch/ecs |
| 67 | + │ └─ status: StatusOK |
| 68 | + ├─ processor:attributes/dataset |
| 69 | + │ └─ status: StatusOK |
| 70 | + ├─ processor:elasticinframetrics |
| 71 | + │ └─ status: StatusOK |
| 72 | + ├─ processor:resource/process |
| 73 | + │ └─ status: StatusOK |
| 74 | + ├─ processor:resourcedetection |
| 75 | + │ └─ status: StatusOK |
| 76 | + └─ receiver:hostmetrics/system |
| 77 | + └─ status: StatusOK |
| 78 | +---- |
| 79 | ++ |
| 80 | +. Congratulations! Host logs and metrics are now being collected and ingested by the {agent} service running an OTel Collector instance. |
| 81 | +For further details about OpenTelemetry collector components supported by {agent}, refer to the link:https://github.com/elastic/elastic-agent/tree/main/internal/pkg/otel#components[Elastic Distribution for OpenTelemetry Collector README]. |
0 commit comments