To fully utilize the power of the Metrics API v2 queries from within the Dynatrace web UI, use Data Explorer in Advanced mode.
In Advanced mode, you can:
metric A
+ metric B
.You can start building a simple query through the web UI and then turn on Advanced mode to see the underlying query.
For example, if you start with this query with Advanced mode off:
you will see this when you turn Advanced mode on:
The underlying query code is displayed in the form in which it is passed to the Metrics API v2:
builtin:host.cpu.usage:splitBy("dt.entity.host"):avg:auto:sort(value(avg,descending)):limit(20)
For simple queries where you need one of the following transformations, you can turn advanced mode off again:
For a detailed description of the individual transformations, see metric selector.
Turning advanced mode off is possible only if the transformations you edited in advanced mode were added when advanced mode was off.
For example, if you initially applied a sort transformation with advanced mode off, you can change the sort order from ascending
to descending
with advanced mode on and then switch advanced mode back off. However, once you add new parts to the query—for example, by adding transformations like a timeshift or metric expressions, which aren't yet possible with advanced mode turned off—you can't switch advanced mode back off and continue working.
The main functions of the query editor are the same whether Advanced mode is turned on or off:
To add a metric, select Add metric to add a row (another metric) to the query.
To duplicate a metric, select More (…) > Duplicate in a row to duplicate that row (metric).
To delete a metric, select More (…) > Delete in a row to delete that row (metric).
To reorder metrics, select and drag the metric to a new position in the list of metrics. Rerun the query to see your changes.
The order in which metrics are listed in your query affects the following:
To try the query, select Run query. The text next to the Run query button displays the status of the most recent run.
The main difference is in how you edit the query and the number of possibilities available:
The easiest way to select metrics for a query is to start with Advanced mode turned off.
Insert the pointer/cursor into a row and start typing a metric name. Matching metrics are listed.
For example, type cpu usage
and then select builtin:host.cpu.usage
from the list.
You can select commonly applied aggregations, dimensions, and transformations:
Average
, Count
, Maximum
, Minimum
, Sum
, Median
, Percentile 10th
, Percentile 75th
, or Percentile 90th
.The selected aggregation is applied after the Split by. For example, if you select Percentile 10th
and split by Host
for a gauge metric such as builtin:host.cpu.idle
, the percentile is calculated on the values after splitting by host.
Turn Advanced mode on.
Edit the results as needed.
To add a metric in Advanced mode
Insert the pointer/cursor into a row and start typing a metric key. Matching metrics are listed.
For example, type host.cpu
and then select builtin:host.cpu.usage
from the list.
You need to add all transformations manually.
In the edit box:
:
) to list what you can add at that insertion point, and then select from the list.An operand is a metric or a number.
()
. You can also use brackets to enforce precedence.For full details on writing metric queries, see:
Metric expressions enable you to apply simple arithmetic operations on operands (metrics or numbers).
For example, this expression calculates the ratio (as a percentage) of two metrics:
((metric1)/(metric2))*(100)
Building on the example above, we have the following basic components to work with:
()
+
, -
, *
, /
-()
Arithmetic operations use the data points of tuples (unique combinations of metric—dimension—dimension value) of metrics. Identical tuples of each metric are paired and then their data points are aligned. For details, see Metrics API - Metric expressions.
Learn how to:
This example shows how to transform a gauge metric into a delta count metric.
With Advanced mode turned on, we have assembled the following gauge metric:
builtin:cloud.kubernetes.pod.containerRestarts:splitBy()
by making the following series of selections from the options offered in the editor:
Select metric: Type part of the metric key until you see the metric you want to select.
Select splitBy: Type a colon (:
) followed by a partial search string for what you want to add (in this case, splitBy
), then select it from the list.
Intermediate state:
builtin:cloud.kubernetes.pod.containerRestarts:splitBy()
But we decide we want to show it as a delta count metric.
Select avg: Type a colon (:
) followed by a partial search string for avg
, then select it from the list.
Select delta: Type a colon (:
) followed by a partial search string for delta
, then select it from the list.
Final state:
builtin:cloud.kubernetes.pod.containerRestarts:splitBy():avg:delta
Run the query.
Learn how to:
In this example, we want to display the error rate for a conversion page. We can start with these metrics:
builtin:apps.web.action.count.load.browser
)builtin:apps.web.action.countOfErrors
)But simple counts don't tell a whole story. Based on the action and error counts, we want to calculate a third metric to report the conversion page error rate. The query for the third metric will divide the error count by the action count and filter for the page name.
We can create this query with almost no typing.
With Advanced mode turned off, select the metrics, aggregations, and filters.
With Advanced mode turned on, view the query code.
Copy and paste the contents of edit box B into edit box A, combining the two queries with added parentheses and a division sign, and then delete B.
If A is the first operand:
builtin:apps.web.action.countOfErrors:filter(and(or(in("dt.entity.application_method",entitySelector("type(application_method),entityName.equals(~"loading of page /easytravel/home~")"))))):splitBy():sum:auto:sort(value(sum,descending)):limit(20)
and B is the second operand:
builtin:apps.web.action.count.load.browser:filter(and(or(in("dt.entity.application_method",entitySelector("type(application_method),entityName.equals(~"loading of page /easytravel/home~")"))))):splitBy():sum:auto:sort(value(sum,descending)):limit(20)
we want to divide (A)/(B)
:
((builtin:apps.web.action.countOfErrors:filter(and(or(in("dt.entity.application_method",entitySelector("type(application_method),entityName.equals(~"loading of page /easytravel/home~")"))))):splitBy():sum:auto:sort(value(sum,descending)):limit(20))/(builtin:apps.web.action.count.load.browser:filter(and(or(in("dt.entity.application_method",entitySelector("type(application_method),entityName.equals(~"loading of page /easytravel/home~")"))))):splitBy():sum:auto:sort(value(sum,descending)):limit(20))
The result should be something like this:
Run the query.
Now you can add thresholds and pin the query to a dashboard.
Learn how to add context to your visualizations such as line charts in order to answer the question, "What's considered normal?"
When looking at data on your dashboards, the lines or single values alone often are quite useless, particularly to new users, who may lack the expertise and experience to quickly judge whether a spike on a line chart or a certain number can be considered an anomoly. Adding context to your visualizations can make all the difference to enabling better and faster interpretation.
In this example, we learn how to duplicate your metric and then apply the :timeshift
transformation to add context to your line charts.
We start with builtin:apps.web.largestContentfulPaint.load.browser
, a built-in Core web vital metric that gives you the largest contentful paint measurements for all load actions for all your web applications.
We can create this query with almost no typing.
The final query code for A and B should look something like this (depending on your selections in step 1):
A without timeshift:
builtin:apps.web.largestContentfulPaint.load.browser:splitBy():percentile(75):auto:sort(value(percentile(75),descending)):limit(10)
B with a timeshift applied:
builtin:apps.web.largestContentfulPaint.load.browser:timeshift(-1w):splitBy():percentile(75):auto:sort(value(percentile(75),descending)):limit(10)
Learn how to use the entity selector and relationships to filter a metric by the values of a related entity.
In this example, we:
builtin:cloud.kubernetes.node.cores
in
filter for the Kubernetes nodes like dt.entity.kubernetes_node
Let's break the entity selector down by its components to better explain them before looking at the final query:
type(KUBERNETES_NODE)
defines the type of the entity we are looking for.toRelationships.IS_KUBERNETES_CLUSTER_OF_NODE(
defines the relationship between the node (left part) and the cluster (right part; see below). Remember, we want all Kubernetes nodes in a given cluster so it can be interpreted as such: "from the entity I defined before (the Kubernetes node), I am looking for all Kubernetes clusters of that node.type(KUBERNETES_CLUSTER),entityId(KUBERNETES_CLUSTER-A943C5CF0A41A684))")))
defines the entity of the right side of this relationship as a Kubernetes clusteran cluster and the given entity ID.The final query looks like this:
(builtin:cloud.kubernetes.node.cores:avg):filter(in("dt.entity.kubernetes_node",entitySelector("type(KUBERNETES_NODE),toRelationships.IS_KUBERNETES_CLUSTER_OF_NODE(type(KUBERNETES_CLUSTER),entityId(KUBERNETES_CLUSTER-A943C5CF0A41A684))")))