Skip to content

Commit

Permalink
Merge pull request #16939 from tclayton-newr/expand-getField-examples
Browse files Browse the repository at this point in the history
chore(metrics): Expand getField examples to include long hand queries
  • Loading branch information
rhetoric101 committed Apr 15, 2024
2 parents d8e345e + 341e91c commit 3ad9277
Showing 1 changed file with 32 additions and 10 deletions.
Expand Up @@ -201,29 +201,51 @@ If used in a query, `myNeatProcess.%.duration` will return results for all three

There are [multiple types of `Metric` data](/docs/data-apis/understand-data/metric-data/metric-data-type/#metric-types) (for example, `gauge` and `count`) and each type has several associated <DoNotTranslate>**fields**</DoNotTranslate>. For details on the types of fields available, see [`getField()`](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#func-getfield).

You can use `getField()` to extract those fields. For example, if you want to use a single value within a metric to do a comparison in a `WHERE` clause, you can use `getField(metricName, field)` or `metricName[field]`.
You can use `getField()` to extract those fields. For example, if you want to use a single value within a metric to do a comparison in a `WHERE` clause, you can use `getField(metricName, field)` or the shorthand syntax `metricName[field]`.

<CollapserGroup>
<Collapser
id="example-list-gauge-metrics"
title="List of gauge metrics"
id="example-list-names-host"
title="List all metric names for a particular host"
>
This example query returns a list of gauge metrics:
The average value of a metric is computed as `total` over `count`, so the following query returns metric data where the result of the `average()` value function is greater than 2.

```
FROM Metric SELECT uniques(metricName) WHERE %[type] = 'gauge'
FROM Metric
SELECT average(apm.service.transaction.duration)
WHERE appName = 'MyApp'
AND getField(apm.service.transaction.duration, total) / getField(apm.service.transaction.duration, count) > 2
```
</Collapser>

Or, you can use the shorthand:

```
FROM Metric
SELECT average(apm.service.transaction.duration)
WHERE appName = 'MyApp'
AND apm.service.transaction.duration[total] / apm.service.transaction.duration[count] > 2
```
</Collapser>
<Collapser
id="example-list-names-host"
title="List all metric names for a particular host"
id="example-list-gauge-metrics"
title="List of gauge metrics"
>
The average value of a metric is computed as `total` over `count`, so the following query returns metric data where the result of the `average()` value function is greater than 2.
This example query returns a list of gauge metrics:

```
FROM Metric SELECT average(apm.service.transaction.duration) WHERE appName = 'MyApp' AND apm.service.transaction.duration[total] / apm.service.transaction.duration[count] > 2
FROM Metric
SELECT uniques(metricName)
WHERE getField(%, type) = 'gauge'
```

Or, you can use the shorthand:
```
FROM Metric
SELECT uniques(metricName)
WHERE %[type] = 'gauge'
```

Note the use of the `%` wildcard to target any matching `metricName`.
</Collapser>
</CollapserGroup>

Expand Down

0 comments on commit 3ad9277

Please sign in to comment.