Skip to content

Commit

Permalink
Merge pull request #18997 from newrelic/daily-release/Oct-17-2024-11_05
Browse files Browse the repository at this point in the history
Daily release/oct 17 2024 11 05
  • Loading branch information
jeff-colucci authored Oct 17, 2024
2 parents 0718ec9 + 1e200d0 commit 8cfa80d
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 18 deletions.
156 changes: 156 additions & 0 deletions src/content/docs/apis/rest-api-v2/migrate-to-nrql.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: Migrate to NRQL
tags:
- APIs
- REST API v2
- NRQL
translate:
- jp
metaDescription: 'How to migrate your REST API v2 queries to NRQL queries.'
freshnessValidatedDate: never
---

## List metric names for your app

To view the metric names available for your application:

```nrql
SELECT uniques(metricTimesliceName) FROM Metric WHERE appId = '$APP_ID' AND newrelic.timeslice.value IS NOT NULL SINCE 30 MINUTES AGO LIMIT MAX
```

You can also filter using the application name:

```nrql
SELECT uniques(metricTimesliceName) FROM Metric WHERE appName = '$APP_NAME' AND newrelic.timeslice.value IS NOT NULL SINCE 30 MINUTES AGO LIMIT MAX
```

Or using a specific agent (host):

```nrql
SELECT uniques(metricTimesliceName) FROM Metric WHERE realAgentId = '$AGENT_ID' AND newrelic.timeslice.value IS NOT NULL SINCE 30 MINUTES AGO LIMIT MAX
```

## Get your app's metric timeslice data values

The REST API v2 accepts a list of metric names and a list of values to fetch metric timeslice data.

The metric names are the same, you can filter them with the `metricTimesliceName` field in your NRQL query.

Each API value can be mapped to a NRQL function, you can refer to the table below.

Example, for the following API request:

```bash
curl -X GET "https://api.newrelic.com/v2/applications/${APP_ID}/metrics/data.json" \
-H "X-Api-Key:${API_KEY}" -i \
-d 'names[]=HttpDispatcher&values[]=average_call_time&values[]=call_count'
```

You would use the following query:

```nrql
SELECT COUNT(newrelic.timeslice.value) AS call_count, average(newrelic.timeslice.value) * 1000 AS average_call_time
FROM Metric
WHERE appId = $APP_ID AND metricTimesliceName = 'HttpDispatcher'
```

| Value (RPM) | NRQL Function |
| -------------------------- | ------------------------------------------------------------------------------------------------- |
| average_response_time | average(newrelic.timeslice.value) \* 1000 |
| calls_per_minute | rate(count(newrelic.timeslice.value), 1 minute) |
| call_count | count(newrelic.timeslice.value) |
| min_response_time | min(newrelic.timeslice.value) \* 1000 |
| max_response_time | max(newrelic.timeslice.value) \* 1000 |
| average_exclusive_time | average(newrelic.timeslice.value['totalExclusive'] / newrelic.timeslice.value['count']) \* 1000 |
| average_value | average(newrelic.timeslice.value) |
| total_call_time_per_minute | rate(sum(newrelic.timeslice.value), 1 minute) |
| requests_per_minute | rate(count(newrelic.timeslice.value), 1 minute) |
| standard_deviation | stddev(newrelic.timeslice.value) \* 1000 |
| average_time | average(newrelic.timeslice.value) \* 1000 |
| count | count(newrelic.timeslice.value) |
| used_bytes_by_host | average(newrelic.timeslice.value) \* 1024 \* 1024 |
| used_mb_by_host | average(newrelic.timeslice.value) |
| total_used_mb | sum(newrelic.timeslice.value) |
| average_call_time | average(newrelic.timeslice.value) \* 1000 |
| total_value | sum(newrelic.timeslice.value) |
| min_value | min(newrelic.timeslice.value) |
| max_value | max(newrelic.timeslice.value) |
| rate | rate(sum(newrelic.timeslice.value), 1 second) |
| throughput | rate(count(newrelic.timeslice.value), 1 second) |
| as_percentage | average(newrelic.timeslice.value) \* 100 |
| errors_per_minute | rate(count(newrelic.timeslice.value), 1 minute) |
| error_count | count(newrelic.timeslice.value) |
| total_time | sum(newrelic.timeslice.value) \* 1000 |
| sessions_active | average(newrelic.timeslice.value) |
| total_visits | sum(newrelic.timeslice.value) |
| percent | average(newrelic.timeslice.value) \* 100 |
| percent (`CPU/User Time`) | 100 \* sum(newrelic.timeslice.value) / `$TIME_WINDOW_IN_SECONDS` |
| time_percentage | 100 \* sum(newrelic.timeslice.value) / `$TIME_WINDOW_IN_SECONDS` |
| utilization | 100 \* sum(newrelic.timeslice.value) / `$TIME_WINDOW_IN_SECONDS` |
| visits_percentage | 100 \* sum(newrelic.timeslice.value) / `$TIME_WINDOW_IN_SECONDS` |

If the function includes `$TIME_WINDOW_IN_SECONDS`, it means that you need to replace it with the time window you want to query.

Example, if you query a 30 minutes time window, you would replace `$TIME_WINDOW_IN_SECONDS` with `1800`.

### Apdex metrics

| Value (RPM) | NRQL Function |
| ------------- | ---------------------------------------------------------------------------------- |
| score | apdex(newrelic.timeslice.value) |
| s | apdex(newrelic.timeslice.value) or count(newrelic.timeslice.value) |
| t | apdex(newrelic.timeslice.value) or sum(newrelic.timeslice.value) |
| f | apdex(newrelic.timeslice.value) or sum(newrelic.timeslice.value['totalExclusive']) |
| count | apdex(newrelic.timeslice.value) |
| value | apdex(newrelic.timeslice.value) |
| threshold | max(newrelic.timeslice.value) |
| threshold_min | min(newrelic.timeslice.value) |

### EndUser & Mobile metrics

These metrics will return the same result as what you would get from the REST API v2, but some results may differ from what you see on the New Relic UI.
This is because the UI uses events instead of timeslice data.
If you want to get the same results as the UI, you should query the events directly.

| Value (RPM) | NRQL Function |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| average_response_time | sum(newrelic.timeslice.value) / count(newrelic.timeslice.value) \* 1000 |
| error_percentage | (filter(count(newrelic.timeslice.value), WHERE metricTimesliceName = 'EndUser/errors') / filter(count(newrelic.timeslice.value), WHERE metricTimesliceName = 'Browser')) |
| average_fe_response_time | sum(newrelic.timeslice.value['totalExclusive']) / count(newrelic.timeslice.value) \* 1000 |
| average_be_response_time | 1000 \* (sum(newrelic.timeslice.value) - sum(newrelic.timeslice.value['totalExclusive'])) / count(newrelic.timeslice.value) |
| average_network_time | (sum(newrelic.timeslice.value) - sum(newrelic.timeslice.value['totalExclusive']) - sum(newrelic.timeslice.value['sumOfSquares'])) / count(newrelic.timeslice.value) |
| total_network_time | (sum(newrelic.timeslice.value) - sum(newrelic.timeslice.value['totalExclusive']) - sum(newrelic.timeslice.value['sumOfSquares'])) |
| network_time_percentage | (sum(newrelic.timeslice.value) - sum(newrelic.timeslice.value['totalExclusive']) - sum(newrelic.timeslice.value['sumOfSquares'])) / `$TIME_WINDOW_IN_SECONDS` |
| total_fe_time | sum(newrelic.timeslice.value['totalExclusive']) |
| fe_time_percentage | 100 \* sum(newrelic.timeslice.value['totalExclusive']) / `$TIME_WINDOW_IN_SECONDS` |
| average_dom_content_load_time | average(newrelic.timeslice.value) \* 1000 |
| average_queue_time | average(newrelic.timeslice.value['totalExclusive']) \* 1000 |
| total_queue_time | sum(newrelic.timeslice.value['totalExclusive']) \* 1000 |
| total_dom_content_time | sum(newrelic.timeslice.value) \* 1000 |
| total_app_time | sum(newrelic.timeslice.value['sumOfSquares']) |
| average_app_time | sum(newrelic.timeslice.value['sumOfSquares']) / count(newrelic.timeslice.value) |
| average_sent_bytes | sum(newrelic.timeslice.value['totalExclusive']) \* 1000 |
| average_received_bytes | 1000 \* sum(newrelic.timeslice.value) / count(newrelic.timeslice.value) |
| launch_count | count(newrelic.timeslice.value) |

### Timeseries and summaries

By default, the REST API returns a series of metric data values based. To obtain the average of these values, you would include `&summarize=true` in your API call.

In NRQL, that's the opposite. You get a summary by default, and you can get the timeseries by adding `TIMESERIES` to your query.

Another difference is that the default time window of the REST API is 30 minutes, while in NRQL, it is 1 hour.

## Query multiple metrics

You can still query multiple metrics at once with NRQL, here's an example:

```nrql
SELECT
FILTER(1000 * AVERAGE(newrelic.timeslice.value), WHERE metricTimesliceName = 'HttpDispatcher') as average_response_time,
FILTER(count(newrelic.timeslice.value), WHERE metricTimesliceName = 'Errors/all') as error_count,
FILTER(average(newrelic.timeslice.value), WHERE metricTimesliceName = 'Memory/Heap/Max') as used_mb_by_host
FROM Metric
WHERE appName = '$APP_NAME'
SINCE 1 day ago
```
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
The .NET agent `v9.2.0` or higher automatically instruments the [Microsoft.Azure.Cosmos](https://www.nuget.org/packages/Microsoft.Azure.Cosmos) library.

* Minimum supported version: 3.17.0
* Latest verified compatible version: 3.23.0
* Latest verified compatible version: 3.44.0
* Versions 3.35.0 and higher are supported beginning with .NET agent v10.32.0
</td>
</tr>

Expand Down Expand Up @@ -433,7 +434,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
Use [Oracle.ManagedDataAccess.Core](https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/)

* Minimum supported version: 23.4.0
* Latest verified compatible version: 23.5.1
* Latest verified compatible version: 23.6.0

Older versions of `Oracle.ManagedDataAccess.Core` may be instrumented, but have not been tested and are not supported.
</td>
Expand Down Expand Up @@ -476,7 +477,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
<td>
Minimum supported version: 2.3.0

Latest verified compatible version: 2.26.0
Latest verified compatible version: 2.29.0

Beginning in agent version 10.12.0, the following methods added in or after driver version 2.7 are instrumented:
* IMongoCollection.CountDocuments[Async]
Expand Down Expand Up @@ -549,7 +550,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

<DNT>**Elastic.Clients.Elasticsearch**</DNT>
* Minimum supported version: 8.0.0
* Latest verified compatible version: 8.14.6
* Latest verified compatible version: 8.15.8
* Versions 8.10.0 and higher are supported beginning with .NET agent v10.20.1
* Versions 8.12.1 and higher are supported beginning with .NET agent v10.23.0

Expand Down Expand Up @@ -674,7 +675,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
10.23.0
</td>
<td>
3.7.403.4
3.7.404.5
</td>

</tr>
Expand Down Expand Up @@ -738,7 +739,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
9.7.0
</td>
<td>
3.1.1
4.0.1
</td>
</tr>

Expand All @@ -753,7 +754,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
9.7.0
</td>
<td>
5.3.2
5.3.14
</td>
</tr>

Expand All @@ -768,7 +769,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
10.0.0
</td>
<td>
8.0.0
8.0.1
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -863,7 +864,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

* Minimum supported version: 7.1.0

* Latest verified compatible version: 8.1.1
* Latest verified compatible version: 8.2.5
</td>
</tr>

Expand All @@ -877,7 +878,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

* Minimum supported version: 3.7.0

* Latest verified compatible version: 3.7.400.19
* Latest verified compatible version: 3.7.400.33
</td>
</tr>

Expand Down Expand Up @@ -1385,7 +1386,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
<td>
Minimum supported version: 2.3.0

Latest verified compatible version: 2.26.0
Latest verified compatible version: 2.29.0

Beginning in agent version 10.12.0, the following methods added in or after driver version 2.7 are instrumented:
* `IMongoCollection.CountDocuments[Async]`
Expand Down Expand Up @@ -1620,7 +1621,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

Minimum supported version: 105.2.3

Latest verified compatible version: 111.4.0
Latest verified compatible version: 112.1.0

Known incompatible versions: 106.8.0, 106.9.0, 106.10.0, 106.10.1
</td>
Expand Down Expand Up @@ -1703,7 +1704,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
10.23.0
</td>
<td>
3.7.403.4
3.7.404.5
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -1766,7 +1767,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
9.7.0
</td>
<td>
3.1.1
4.0.1
</td>
</tr>

Expand All @@ -1781,7 +1782,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co
9.7.0
</td>
<td>
5.3.2
5.3.14
</td>
</tr>

Expand Down Expand Up @@ -1900,7 +1901,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

* Minimum supported version: 7.1.0

* Latest verified compatible version: 8.1.1
* Latest verified compatible version: 8.2.5
</td>
</tr>

Expand All @@ -1914,7 +1915,7 @@ Want to try out our .NET agent? [Create a New Relic account](https://newrelic.co

* Minimum supported version: 3.7.0

* Latest verified compatible version: 3.7.400.19
* Latest verified compatible version: 3.7.400.33
</td>
</tr>

Expand Down
Loading

0 comments on commit 8cfa80d

Please sign in to comment.