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