Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Relic Solution: Metric Timeslice Query Pro-Tips



Hi folks! We support engineers have been playing around with this feature and would like to share some pro-tips we’ve uncovered. Please feel free to share your own in the thread below!

But first off …

What are Metric Timeslice Queries?

In the past, you could only query “event data” using NRQL. Metrics (like those coming from APM) were generally not able to be queried. You could sort of simulate those metrics by doing things like querying the count of Transaction events, for instance, but those were inaccurate and kludgy.

This documentation goes into some detail on how to implement the “metric bridge” that our backend systems use to allow these queries.

I and my colleagues have been using that documentation as a jumping-off point to come up with some interesting and powerful queries that you can use for generating dashboard widgets or even in a NRQL alert condition.

OK, I get it. What’s the first pro-tip?

spoiler alert: it’s APM error rate

Way back, several years ago, there was a thread on these forums which explored ways to query error rate of an application as a percentage. Our very own @alexis came up with what I think is the best solution:

SELECT filter(count(*), WHERE `error.message` IS NOT null)*100 / filter(count(*), WHERE duration IS NOT null) FROM Transaction, TransactionError WHERE appId = {your_app_id}

This was an awesome tool, but since both Transaction and TransactionError are sampled events, meaning only a certain number of them will be collected each minute, you weren’t guaranteed to get accurate results when the throughput of your application got too high. Another limitation was that you couldn’t scope this to a transaction, but were instead limited to looking at error rate by application only.

But now we have metric timeslice queries!

NOW, instead of relying on the usable-but-not-perfect query above to calculate error rate, you can directly query the metrics being produced by your APM agent:

FROM Metric SELECT count(apm.service.transaction.error.count) / count(apm.service.transaction.duration)  WHERE appName = 'My App Name' FACET transactionName TIMESERIES

This returns a timeseries graph showing error rate %, separated out by transaction name. You could, if you wanted, specify only a single transaction to scope into the error rate of just that transaction (which would work great for Key Transactions).

Keep in mind that, when throughput for a transaction drops to 0, error rate will be NULL for that time bucket. That’s because any fraction with a 0 as the denominator results in a non-number.

For now, the apm... attributes are currently undocumented, although our engineering team is working on documentation on how to use those in your queries as well – we should be seeing that soon.

I hope you found this useful. Go ahead and post any of your ideas below!

How to present APM error % in an insights query?

Here’s one! The query below will give you a chart similar to the Apdex chart you’d see in APM, for an application that has a corresponding Browser app set up via auto-instrumentation.

FROM Metric SELECT filter(apdex(newrelic.timeslice.value), WHERE metricTimesliceName = 'Apdex') AS 'App Server', filter(apdex(newrelic.timeslice.value), WHERE metricTimesliceName = 'EndUser/Apdex') AS 'End User' WHERE appName = '{Application name}' TIMESERIES

Please note that metric querying is not available for Browser apps that were installed via copy-and-paste.

What is the logic behind charts that don't allow you to see/tweak the query?