0
0
Elasticsearchquery~5 mins

Application performance monitoring in Elasticsearch

Choose your learning style9 modes available
Introduction

Application performance monitoring helps you see how well your app works. It shows if parts are slow or have errors.

You want to find why your website is slow for users.
You need to check if a new update caused errors.
You want to watch your app's health during busy times.
You want to get alerts when something breaks.
You want to understand user experience by tracking app speed.
Syntax
Elasticsearch
PUT /apm-7.17.0
{
  "settings": {
    "index": {
      "number_of_shards": 1
    }
  },
  "mappings": {
    "properties": {
      "transaction.duration.us": { "type": "long" },
      "transaction.name": { "type": "keyword" },
      "service.name": { "type": "keyword" },
      "timestamp": { "type": "date" }
    }
  }
}

This example creates an index for storing APM data in Elasticsearch.

Fields like transaction.duration.us measure how long a request takes in microseconds.

Examples
Searches the APM index for data from the service named "my-app".
Elasticsearch
GET /apm-7.17.0/_search
{
  "query": {
    "match": { "service.name": "my-app" }
  }
}
Calculates the average transaction duration in microseconds.
Elasticsearch
GET /apm-7.17.0/_search
{
  "aggs": {
    "avg_duration": {
      "avg": { "field": "transaction.duration.us" }
    }
  }
}
Adds a new transaction record to the APM index.
Elasticsearch
POST /apm-7.17.0/_doc
{
  "service.name": "my-app",
  "transaction.name": "GET /home",
  "transaction.duration.us": 150000,
  "timestamp": "2024-06-01T12:00:00Z"
}
Sample Program

This query finds the average response time for the service named "my-app" from the APM data.

Elasticsearch
POST /apm-7.17.0/_search
{
  "size": 0,
  "aggs": {
    "avg_response_time": {
      "avg": {
        "field": "transaction.duration.us"
      }
    }
  },
  "query": {
    "term": {
      "service.name": "my-app"
    }
  }
}
OutputSuccess
Important Notes

APM data is often stored in Elasticsearch indexes with specific mappings for performance metrics.

Use Kibana or other tools to visualize APM data easily.

Keep your APM data size manageable by setting retention policies.

Summary

Application performance monitoring helps track app speed and errors.

Elasticsearch stores and queries APM data using indexes and aggregations.

Average response time is a key metric to watch for app health.