New Relic Insights Query examples with dashboard

New Relic Insights lets you create clear and easy to use dashboards by writing NRQL query which is similar to SQL. The dashboards could include various type of widgets from new mobile users to website performance.  These stats are extremely beneficial as it helps you to provide a better product.

In this tutorial, I’m going to go through some of the NRQL query examples.

New Relic Insights query examples

Finding out the average page duration over a period of a month for mobile users in selected countries

SELECT average(duration) from PageView SINCE last 
month facet countryCode, pageUrl where countryCode IN ('GB', 'US')
and deviceType = 'Mobile'

With mobile users on the rise, this query can help you identify the slow pages of mobile devices on selected countries.

Finding out the average connection setup duration

select average(connectionSetupDuration) from PageView FACET countryCode

This query helps you to identify the average connection setup grouped by country. Website speed is critical these days. You could modify this query to show the speed for only selected countries by using the “WHERE” condition.

Total number of sessions grouped by country

SELECT count(session) FROM PageView FACET countryCode  SINCE 4 weeks ago

If you are receiving traffic from multiple countries, it would be good to have an overview of the sessions.

Finding out the most visited pages grouped by the country code.

SELECT count(pageUrl) FROM PageView 
FACET pageUrl, countryCode 
SINCE last week

To exclude certain pages you could use the “not like ‘%%’ where the condition

Example: we want to exclude the pages that have “login” in the URL

SELECT count(pageUrl) FROM PageView
FACET pageUrl, countryCode
SINCE last week Where pageUrl not like ‘%login%’

Finding out the number of sessions by Platform

SELECT count(session) from PageView
FACET userAgentOS, userAgentName since 4 weeks ago

Finding out how frequent it takes to load pages within X timeframe?

select histogram(duration, 10, 20) from PageView since 3 month ago

The histogram method takes three arguments.

  • Attribute name
  • The maximum value of the sample range (in our example it is 10 seconds)
  • Total number of buckets

We could come to know that 8,161 users have their page loaded between 0.0 to 0.5 seconds. This is great! but we would need to look into bringing more users within this range. The next step would be finding out the which countries our website speed is the slowest and look into ways to improve it.

 Finding out new unique users compared with last week

SELECT uniqueCount(session)  FROM PageView
SINCE 1 week ago COMPARE WITH 1 week AGO

Finding out the number of sessions by device type

SELECT count(session) from PageView facet deviceType

With the queries above you could create your own customized dashboard. Having a dashboard gives you the flexibility to filter out results as well.