Application performance monitoring helps you see how well your app works. It shows if parts are slow or have errors.
Application performance monitoring in Elasticsearch
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
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
Elasticsearch
GET /apm-7.17.0/_search { "query": { "match": { "service.name": "my-app" } } }
Elasticsearch
GET /apm-7.17.0/_search { "aggs": { "avg_duration": { "avg": { "field": "transaction.duration.us" } } } }
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" } } }
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.
Practice
1. What is the main purpose of Application Performance Monitoring (APM) in Elasticsearch?
easy
Solution
Step 1: Understand APM's role
APM is designed to monitor how fast an application runs and to find any errors it produces.Step 2: Match purpose with options
Only To track application speed and detect errors describes tracking speed and errors, which fits APM's main goal.Final Answer:
To track application speed and detect errors -> Option AQuick Check:
APM purpose = Track speed and errors [OK]
Hint: APM = watch app speed and errors [OK]
Common Mistakes:
- Confusing APM with security or backup tools
- Thinking APM manages cluster nodes
- Assuming APM stores user credentials
2. Which Elasticsearch query syntax correctly calculates the average response time from APM data?
easy
Solution
Step 1: Identify aggregation for average
The query uses "avg" aggregation on the field "transaction.duration.us" which stores response times in microseconds.Step 2: Confirm query structure
Size is 0 to avoid returning documents, focusing only on aggregation results, which is correct for average calculation.Final Answer:
GET /apm-*/_search {"size":0, "aggs": {"avg_response_time": {"avg": {"field": "transaction.duration.us"}}}} -> Option CQuick Check:
Average aggregation query = GET /apm-*/_search {"size":0, "aggs": {"avg_response_time": {"avg": {"field": "transaction.duration.us"}}}} [OK]
Hint: Average uses "avg" aggregation with size 0 [OK]
Common Mistakes:
- Using match_all without aggregation
- Using update_by_query instead of search
- Using max aggregation instead of avg
3. Given this Elasticsearch aggregation query on APM data, what is the expected output?
GET /apm-*/_search
{
"size": 0,
"aggs": {
"avg_response_time": {
"avg": { "field": "transaction.duration.us" }
}
}
}medium
Solution
Step 1: Understand aggregation type
The query requests the average of the field "transaction.duration.us" which holds response times in microseconds.Step 2: Match output to aggregation
The output shows an aggregation named "avg_response_time" with a numeric value representing the average, matching {"aggregations":{"avg_response_time":{"value":250000}}}.Final Answer:
{"aggregations":{"avg_response_time":{"value":250000}}} -> Option DQuick Check:
Average aggregation output = {"aggregations":{"avg_response_time":{"value":250000}}} [OK]
Hint: Aggregation output shows "aggregations" with average value [OK]
Common Mistakes:
- Confusing hits total with aggregation result
- Expecting max instead of avg
- Assuming error without checking field existence
4. You run this Elasticsearch query to get average response time but get an error:
Fielddata is disabled on text fields by default. What is the likely cause?medium
Solution
Step 1: Analyze error message
The error says fielddata is disabled on text fields, which means aggregation was attempted on a text field.Step 2: Understand aggregation requirements
Aggregations like average require numeric fields, so using a text field causes this error.Final Answer:
Trying to aggregate on a text field instead of a numeric field -> Option AQuick Check:
Fielddata error = Aggregation on text field [OK]
Hint: Average needs numeric field, not text [OK]
Common Mistakes:
- Blaming index pattern or auth for this error
- Assuming syntax error without checking field type
- Ignoring field data type requirements
5. You want to monitor the average response time for your app but only for transactions with errors. Which Elasticsearch query snippet correctly filters and calculates this?
hard
Solution
Step 1: Identify filter for transactions with errors
Transactions with errors have a non-empty "error.id" field, so we use "exists" query on "error.id".Step 2: Confirm aggregation on filtered data
The aggregation calculates average response time only on filtered documents, which is correct.Final Answer:
{ "size": 0, "query": { "exists": { "field": "error.id" } }, "aggs": { "avg_response_time": { "avg": { "field": "transaction.duration.us" } } } } -> Option BQuick Check:
Filter errors with exists + avg aggregation = { "size": 0, "query": { "exists": { "field": "error.id" } }, "aggs": { "avg_response_time": { "avg": { "field": "transaction.duration.us" } } } } [OK]
Hint: Use exists query to filter error transactions [OK]
Common Mistakes:
- Using empty term query instead of exists
- Calculating average without filtering errors
- Filtering for success instead of errors
