Soru

Zorluk: ZorQuery and Analyze Application Insights Telemetry

An enterprise order processing application sends custom metric telemetry to Azure Application Insights to monitor message queue sizes. A custom metric named 'QueueBacklog' is recorded, and the specific queue's identifier is stored inside a custom dimension named 'QueueName'.

You need to write a Kusto Query Language (KQL) query to find the maximum backlog value for each queue over the last 36 hours. To ensure optimal query performance, you must filter by time range before performing any other operations.

How should you complete the KQL query?

Cevap:kusto
【customMetrics】
| where timestamp > ago(36h) and name == "QueueBacklog"
| extend QueueName = 【tostring】(customDimensions.QueueName)
| summarize MaxBacklog = 【max】(value) by QueueName

Cevap

To complete the query, query the 'customMetrics' table first to load custom metric telemetry, then use the 'tostring' function to cast the dynamic custom dimension property to a string, and finally use the 'max' aggregation function to find the maximum backlog value.
The query starts by targeting the 'customMetrics' telemetry table. To ensure optimization, the time-range filter is applied immediately using the 'where' clause, which restricts processing to the last 36 hours. The dynamic property 'customDimensions.QueueName' is cast to a string type using the 'tostring' function. Finally, the 'max' aggregation function calculates the highest backlog value recorded in the 'value' column, grouping the results by the queue name.

Adım Adım Çözüm

1
Select the correct table for custom metrics telemetry.
The query starts with the 'customMetrics' table name.
Application Insights stores custom metrics recorded via the TrackMetric API inside the 'customMetrics' table.
2
Cast the custom dimension to a string format.
Apply the 'tostring' function to 'customDimensions.QueueName'.
Properties in the 'customDimensions' property bag are dynamic objects. To group by them in KQL summarization, they must be cast to string types using 'tostring()'.
3
Aggregate the maximum metric value.
Use the 'max' aggregation function on the 'value' column.
The 'max' function calculates the highest value recorded for the 'value' field in the 'customMetrics' table across the specified time frame.

Anahtar Kavram

Querying custom metrics and dimensions in Application Insights using optimized KQL filters and aggregations.
Tahmini Süre:2m 0s
Bu soruyu puanla