All Products
Search
Document Center

Elasticsearch:Use a self-managed APM server to collect data to Alibaba Cloud Elasticsearch

Last Updated:Mar 26, 2026

Integrate the open-source Elastic APM stack with Alibaba Cloud Elasticsearch to build an observability pipeline for your services and applications. This guide walks you through deploying a self-managed APM server on an Elastic Compute Service (ECS) instance, instrumenting a Go application with an APM agent, and visualizing the collected data in Kibana.

APM bridges the gap between infrastructure metrics and application-level behavior. While logs and metrics tell you what is happening at the infrastructure layer, APM tells you what is happening inside your application and how users experience it. Integrating APM into your stack lets you:

  • Identify which operations take the longest and why services stop responding

  • Map service dependencies and pinpoint bottlenecks in distributed request flows

  • Track real user experience in browsers and native clients

  • Generate SLA reports and trend analysis from the business perspective

Prerequisites

Before you begin, make sure that you have:

How it works

  1. The APM server receives trace data from APM agents running inside your applications.

  2. The APM server forwards the data to your Alibaba Cloud Elasticsearch cluster.

  3. Kibana reads the data from Elasticsearch and displays it in the APM UI under Observability.

Step 1: Build an APM server

Install the APM server

  1. Connect to your ECS instance as a regular user. See Connect to a Linux instance by using a password or key.

  2. Download the APM server package.

    wget https://artifacts.elastic.co/downloads/apm-server/apm-server-7.10.2-linux-x86_64.tar.gz
  3. Extract the package.

    tar -zxf apm-server-7.10.2-linux-x86_64.tar.gz

Configure the APM server

  1. Go to the APM server directory.

    cd apm-server-7.10.2-linux-x86_64/
  2. Open the configuration file.

    vim apm-server.yml
  3. Update the configuration with your Elasticsearch cluster details.

    Parameter Description
    apm-server.host The address and port the APM server listens on. Format: <IP>:<port>. The value 0.0.0.0:8200 listens on all interfaces.
    output.elasticsearch.hosts The endpoint of your Elasticsearch cluster. Use the internal endpoint if the ECS instance and the cluster are in the same virtual private cloud (VPC). If they are in different VPCs, use the public endpoint and configure a public IP allowlist. See View the basic information of a cluster and Configure a public or private IP address whitelist for an Elasticsearch cluster.
    output.elasticsearch.username The username for Elasticsearch. The default is elastic. To use a custom account, create a role and grant it the required write permissions first. See Use the RBAC mechanism provided by Elasticsearch X-Pack to implement access control.
    output.elasticsearch.password The password for the username above. The elastic account password is set when you create the cluster. To reset it, see Reset the access password for an Elasticsearch cluster.
    apm-server:
      host: "0.0.0.0:8200"
    output.elasticsearch:
      hosts: ["es-cn-*****.elasticsearch.aliyuncs.com:9200"]
      username: "elastic"
      password: "<your-password>"

Start the APM server

Run the following command to start the APM server in the background and redirect output to a log file.

nohup ./apm-server -e > apmserver.log 2>&1 &

The APM server starts, connects to Elasticsearch on the endpoint you specified, and exposes the agent API on port 8200. To verify that the server is running, check apmserver.log for a message confirming the connection to Elasticsearch and that the server is listening on port 8200.

Step 2: Configure an APM agent

This example uses the Elastic APM Go agent. This guide uses environment variables for initial setup.

This guide uses Go as an example. For other languages, install the corresponding Elastic APM agent. See Elastic APM agent documentation for the full list of supported languages and built-in modules.

Install the Go agent

  1. Initialize a Go module for your project.

    sudo go mod init demo
  2. Install the APM agent packages.

    If you see a golang.org xxxx: i/o timeout error, your environment cannot reach golang.org. Change the Go module proxy to a reachable mirror before retrying.
    sudo go get go.elastic.co/apm
    sudo go get go.elastic.co/apm/module/apmhttp

Set APM agent environment variables

  1. Open the shell profile file.

    vim ~/.bash_profile
  2. Add the following environment variables and save the file.

    Variable Default Description
    ELASTIC_APM_SERVICE_NAME Executable file name The name of your service. Allowed characters: letters, digits, hyphens (-), underscores (_), and spaces.
    ELASTIC_APM_SERVER_URL http://localhost:8200 The URL of the APM server. Set this to the address of the server you started in Step 1.
    ELASTIC_APM_SECRET_TOKEN _(none)_ The secret token required by the APM server.
    export ELASTIC_APM_SERVICE_NAME=zijian
    export ELASTIC_APM_SERVER_URL=
    export ELASTIC_APM_SECRET_TOKEN=
  3. Apply the configuration.

    source ~/.bash_profile

Instrument your application

The Elastic APM Go agent provides built-in modules for popular frameworks (such as apmhttp) and a lower-level Tracer API for custom instrumentation. This example uses apmhttp to wrap a standard HTTP server.

  1. Create the application file.

    vim apm.go
  2. Add the following code and save the file.

    package main
    
    import (
      "net/http"
    
      "go.elastic.co/apm/module/apmhttp"
    )
    
    func main() {
      mux := http.NewServeMux()
      http.ListenAndServe(":8080", apmhttp.Wrap(mux))
    }
  3. Run the application.

    sudo go run apm.go

    Once the application is running, the APM agent begins sending trace data to the APM server, which forwards it to your Elasticsearch cluster.

Step 3: View APM data in Kibana

Enable automatic index creation

Alibaba Cloud Elasticsearch enforces index naming conventions. The APM onboarding index created automatically by the APM server does not conform to these conventions, so you must explicitly allow it.

  1. Log in to the Kibana console. See Log on to the Kibana console.

    This guide uses a V7.10 cluster. Login steps may differ for other Elasticsearch versions.
  2. On the Kibana homepage, click Dev tools in the upper-right corner.

  3. On the Console tab, run the following command. Replace 7.10.2 with the version of the APM server you installed.

    PUT _cluster/settings
    {
      "persistent": {
        "action.auto_create_index":"+.*,+apm-7.10.2-onboarding-*,-*"
      }
    }

View monitored services

  1. Click the Navigation bar icon icon in the upper-left corner to expand the navigation pane.

  2. Under Observability, click APM.

  3. On the Services tab, all services monitored by the APM agent are listed.

    View services that are monitored by APM

  4. Click a service name to drill down into its traces, transactions, and performance data.

What's next