New Relic Query
Language
How to Text
Subtitle ‘see’Here
your data
© 2022 New Relic, Inc. All rights reserved
Agenda
01 Querying Events
02 Data Explorer & Query Builder - Starting queries
03 More - Advanced queries
04 Using NRQL for Alerts
05 Chart Challenge - Hands-on practice
© 2022 New Relic, Inc. All rights reserved
Querying Events
© 2022 New Relic, Inc. All rights reserved
Event data in NRDB
• Event data is collected by agents (in NRDB) from across your stack
• Can include custom events
• Events are discrete (individual) and not regular (no schema required)
Dimensional data:
• Each event collects metadata (attributes) about the event that occurred
Example:
Event type: Transaction
Attributes: Transaction Type
Response Code
Request URI
© 2022 New Relic, Inc. All rights reserved
Duration
NRQL Syntax
Build your query around your chosen Event Type
SELECT function(attribute) FROM Event_Type WHERE condition FACET group by
Browser APM Synthetics Mobile
Infrastructure
PageView Transaction SyntheticCheck MobileRequest
SystemSampleSELECT count(*) FROM PageView FACET PageUrl
© 2022 New Relic, Inc. All rights reserved
NRQL example queries
Built around 3 event types
SELECT count(*) FROM PageView FACET PageUrl
SELECT average(duration) FROM Transaction FACET name
SELECT count(result) FROM SyntheticCheck WHERE result !='SUCCESS' FACET error
© 2022 New Relic, Inc. All rights reserved
Data Explorer
Explore & build queries easily with the Data Explorer
3 steps - Choose one of each:
1 Event
2 Plot
3 Dimension
You get a chart instantly. Experiment with different Chart types.
Notice the NRQL query built across the top.
© 2022 New Relic, Inc. All rights reserved
5-7 mins
Lab: Data Explorer
Explore and build queries easily with the Data Explorer
1 Build these queries by selecting the following options.
● Event type: Transaction, Plot Count (*) Dimension Name
This shows throughput for different Transactions
● Event type: Transaction, Plot Count (*) Dimension AppName
This shows throughput for different Applications
○ Try a different visualisation (Bar chart, Pie Chart etc)
● Event type: Transaction, Plot Duration Max Dimension Name
This shows slowest Transactions
● Event type: PageView, Plot Duration Max Dimension PageUrl
This shows slowest Pages. Try a Bar chart and filter to a PageUrl by clicking one from below
2 Try the RAW Data option and explore the attributes for the PageView Event Type
© 2022 New Relic, Inc. All rights reserved
Aggregate your data with
functions
SELECT count(*) FROM Transaction
Throughput for all applications
SELECT max(duration) FROM Transaction
Slowest transactions for all applications
© 2022 New Relic, Inc. All rights reserved
Group your data with Facet
Transactions grouped by name
SELECT count(*) FROM Transaction FACET name
Transactions grouped by response codes
SELECT count(*) FROM Transaction FACET httpResponseCode
Try some other FACETs….
What does LIMIT do after FACET clause?
© 2022 New Relic, Inc. All rights reserved
Get more specific: query part of your data
WHERE
Average duration for a specific application (appName)
SELECT average(duration) FROM Transaction WHERE appName = 'FoodMe'
Count the different response codes from your application (Transactions)
SELECT count(*) FROM Transaction WHERE httpResponseCode != '200'
FACET httpResponseCode
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab:
Lab: NRQL
NRQLQuery
QueryBuilder
Builder- NRQL Mode
- NRQL Mode
Explore the data with a query, then add some charts to a dashboard
1 Explore the data: Try this query in the Query builder and explore the results:
Choose TABLE view
● SELECT * FROM Transaction
2 Throughput for transactions by name: Aggregate with a ‘count all’ function, and group by ‘name’ using
the FACET clause
● SELECT count(*) FROM Transaction FACET Name
● Add this chart to your dashboard
3 Throughput for transactions by….. Try the same query but with different FACET clauses (eg. host,
httpresponse code etc)
● SELECT count(*) FROM Transaction FACET httpResponseCode
● Add this chart to your dashboard
© 2022 New Relic, Inc. All rights reserved 12
5 mins
Lab: Starting Queries with FROM
Start queries with FROM for better help with attribute choices:
1 FROM ____________ SELECT ________________
Count all the PageViews on your site
2 FROM ____________ SELECT ______________ FACET _____________
Count all Pageviews grouped by country
3 FROM _____________ SELECT ____________WHERE ________ FACET ______
Select Max duration of Pageviews (slowest) from a specific country grouped by Page url
© 2022 New Relic, Inc. All rights reserved
Plot data over time with TIMESERIES
SINCE, UNTIL, COMPARE WITH, TIMESERIES
Average duration for a PageView over the past week
SELECT average(duration) FROM PageView SINCE 1 week AGO TIMESERIES
Compare (Trending)
SELECT average(duration) FROM PageView SINCE 1 week AGO COMPARE WITH 1 week AGO TIMESERIES
Control the bucket size
SELECT average(duration) FROM PageView SINCE 1 week AGO COMPARE WITH 1 week AGO TIMESERIES 2 day
—------------------------------------
Average duration for PageViews for a specific time frame
SELECT average(duration) FROM PageView SINCE 5 days AGO UNTIL 3 days ago TIMESERIES
How many unique visitors on my site right now (almost)
SELECT uniqueCount(session) FROM PageView SINCE 5 minutes AGO
© 2022 New Relic, Inc. All rights reserved
Expose more data from a single query with:
Multi-Function and Multi-Facet
Compare different performance data for different pages on your site (PageViews grouped by PageUrl)
SELECT max(duration), average(duration) FROM PageView FACET PageUrl
Worst page load durations broken out by browser type, country code, city
SELECT max(duration) FROM PageView FACET userAgentName, countryCode, city
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab: Multi function/Facet Queries
Add these PageView queries to your dashboard:
1 SELECT ___________ FROM PageView FACET ___________ , ______________
Select a Count all function of Pageviews grouped by Device and CountryCode
2 SELECT _________(duration), average(__________) FROM _________ FACET pageUrl
Select average Pageview duration as well as average backend duration from the PageViews on
your site (Try a TABLE chart type)
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab: Query Builder
Pseudo code into queries
We want to answer the following PageView performance questions. Choose the Demotronv2
Account as the data source and add these charts to your dashboard:
1 What’s the worst (max) page load duration in my app called ‘WebPortal’ (appname) in the
past 24 hours ? _______________________________
How does my average page load duration over past 7 days compare with the 7 days
2 before
(The time specified by COMPARE WITH is relative to the time specified by SINCE or UNTIL)
3 Which cities (FACET) and pages (FACET PageUrl) are experiencing the worst page loads
in my app called ‘WebPortal’ over the past 24 hours ? _____________________________________
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab: More Event Types
Add some of these queries to your dashboard:
Mobile, MobileRequest, SyntheticCheck, SystemSample
1 Infrastructure: SystemSample
SELECT average(cpuPercent) FROM SystemSample FACET `entityName` limit 20
or
SELECT average(diskUsedPercent) from SystemSample facet entityName limit 20
2 Synthetics:: SyntheticCheck
or SELECT count(*) FROM SyntheticCheck FACET result
SELECT average(duration) FROM SyntheticCheck FACET monitorName
3 Mobile: Mobile, MobileRequest
or SELECT count(*) AS 'sessions' FROM Mobile SINCE 1 week ago
SELECT count(*) from MobileCrash SINCE 1 day ago facet deviceModel
© 2022 New Relic, Inc. All rights reserved
Writing NRQL Tips
1 Start with SELECT or FROM (any order)
2 Pick FROM your main EVENT type (from different data sources eg PageView, Transaction etc)
3 Use SPACE BAR or Up/Down arrows in lists or TAB to autocomplete parts of your query
4 Use COMMAS to add Multiple Columns or attributes from a data set
5 If you get Syntax Errors simplify the query and rebuild it step by step, or build it in Basic Mode
first then convert it
* Learn more at our docs site :
** Try the NRQL Lessons App in
© 2022 New Relic, Inc. All rights reserved
Dashboards
▪ Keep an eye on your most
critical performance metrics
quickly by adding them to a
custom dashboard.
▪ Build ANY dashboard you want
with ANY data you want – no
coding involved.
▪ Diagnose problems faster and
enhance collaboration across
teams
© 2022 New Relic, Inc. All rights reserved
Interactive Dashboards & Collaboration
Link FACETS to filter charts across a Dashboard (easier for users than using the filter bar)
Link a (‘general’) Dashboard to another (‘specific’) related Dashboard
EG. SELECT Count(*) FROM Transaction FACET name
Type: Bar
Link facets to
current dashboard
© 2022 New Relic, Inc. All rights reserved
5 mins
Dashboard features
Find the ‘Buried dashboard’ in ‘Demotron V2’ and explore it:
Notice the needle is not correlated across all 3 Timeseries charts?
1 Try a ‘Drag zoom’ across one of the charts to synchronise them
2 Reset the charts to their individual time periods using TimePicker > Default
3 Use the Search box to filter to FACET attributes, or click on Filterable charts. Clear the Filter.
Brush zoom Consistent Facet Colours Correlated Needle
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab: Challenge yourself!
More Advanced Queries
Try adding these queries to your dashboard:
1 Show the 3 slowest transactions (LIMIT)
___________________________________________________________________
2 Compare active unique sessions on your site in the last 5 minutes with 30 minutes earlier
(uniqueCount(sessionID))
___________________________________________________________________
3 Show a chart of 500 response codes and any details
___________________________________________
4 Create a table of throughput through your applications (FACET) and make the app names
interactive filters ___________________________________________________________________
© 2022 New Relic, Inc. All rights reserved
Advanced NRQL
© 2022 New Relic, Inc. All rights reserved
Histogram
SELECT histogram(attribute, ceiling [, number of buckets])
FROM Event_Type SINCE 1 hour ago
Example:
“Show me a Histogram of response times ranging up to 10 seconds over 20 buckets”
SELECT histogram(duration, 10, 20) FROM PageView SINCE 1 week ago
*Use histogram() with a FACET clause to generate a heatmap chart
© 2022 New Relic, Inc. All rights reserved
5 mins
Lab: Histogram
1 Fill in the blanks _____________ and write the following query in a New Relic account
“Show me a Histogram of back-end response times ranging up to 2 seconds with 10 buckets”:
SELECT histogram(_________________, _______, _______) FROM _______________ SINCE 1 week
ago
2 Refine the settings of your histogram:
• Adjust the ceiling to a smaller value and increase the number of buckets to get smaller
steps
• When you’re happy with the distribution save your new Histogram chart
© 2022 New Relic, Inc. All rights reserved
Funnel
SELECT funnel(attribute, Step A, Step B)
Example:
SELECT funnel(session, WHERE pageUrl LIKE '%/' AS'Homepage',
WHERE pageUrl LIKE '%/browse/plans' AS 'Click Product',
Step A Label
WHERE pageUrl LIKE '%login.jsp' AS 'Login',
Step B Label
WHERE pageUrl LIKE '%/checkout' AS 'Confirm')
© 2022 New Relic, Inc. All rights reserved
FACET CASES
Break out your data by more complex conditions
SELECT ...
FACET CASES (WHERE attribute operator value, WHERE attribute operator value, ... )
Eg.
Group your PageView data into categories like < 1 second, from 1 to 10 secs, and > 10 seconds
SELECT count(*) FROM PageView
FACET CASES (WHERE duration < 1, WHERE duration > 1 and duration < 10, WHERE duration > 10)
Page Load Time by Category query
SELECT average(duration) FROM PageView FACET CASES( WHERE pageUrl like '%/index.html' AS 'Home Page',
WHERE pageUrl like '%/browse/%' AS 'Product Page', WHERE pageUrl like '%/shoppingcart' AS 'Cart Page', WHERE
pageUrl LIKE '%/checkout' AS 'Purchased')
TIMESERIES since 1 day ago
© 2022 New Relic, Inc. All rights reserved
Metrics vs. Events
Event: Immutable, timestamped record of
1 a discrete action
Eventn
● Ad-hoc queries (not known in advance)
..attribute 1 ● Retention: Generally short to medium term
..attribute 2 ● Find the needle in a haystack
..attribute 3
..attribute n
time tn
Count: 1000
Average: 536 Metric: Representation of data
Sum: 536,253
2 measured over interval of time
Min: 357 ● Well-defined and common KPIs defined in advance
Max: 6,986 ● Retention: 13 months (roll-ups), 30 days (raw data)
● Summarize info about the haystack
© 2022 New Relic, Inc. All rights reserved
The value of Event data changes over time
Use aggregated metrics rules to
reduce long-term storage costs
Events and increase query speed.
Value of
raw data Rules for querying Metric data type
Metrics
t
Time / retention costs
© 2022 New Relic, Inc. All rights reserved
Dashboards & NRQL
Use these ideas to continue your NRQL knowledge after this course:
1 Build charts around the Transaction
3 Build charts around the SystemSample
event type to find out about your event type to find out about your hosts:
backend applications
CPU, Memory, Disk free, Load average
What throughput do you have across your
applications, your hosts, what response codes you
are getting, how many 500s, average duration of
4 Build charts around the MobileRequest or
transactions grouped by name SyntheticCheck event type to find out
about mobile app crashes or ping check
Build charts around the PageView event
2 type to find out about:
failures:
Mobile Crashes, Synthetic check results or performance
Where your users are from, popular pageUrls, slow
pages, what devices and browsers are being used,
throughput trends (compare) by day/week
© 2022 New Relic, Inc. All rights reserved
Using NRQL in Alerts
Query results
• Queries must return a number.
• The alert condition works by evaluating that returned number against the thresholds you
set.
Threshold Types
Static Anomaly - Baseline
Some elements of NRQL used in
● simplest type ● self-adjusting charts don’t make sense in the
condition based streaming context of alerts.
● Create a condition on the past
based on the behavior of the
numeric value monitored
returned values
© 2022 New Relic, Inc. All rights reserved
5-7 mins
Lab: NRQL Alerts
Explore x 2 ways to create NRQL Alerts in the NRU Training account:
You want to create these NRQL Alert condition for the Pet Clinic app:
Alert when the max duration of my Pageviews take longer than 7 seconds
Alert when the 95th percentile of firstContentPaint) of my Pageviews take longer than 7 seconds
1. Create the query in the Query builder (this is the signal feed for the alert)
2. Choose ‘Create alert’ and set the Threshold settings and create an alert for this
3. Go to the Browser summary page for Pet Clinic app
4. Choose ellipses… Create alert condition from the ‘User-centric page load times’ chart
5. Amend the query to:
SELECT percentile(firstContentfulPaint, 95) FROM PageViewTiming WHERE (appId = 35877322) EXTRAPOLATE
Check our docs site for more NRQL use case examples:
© 2022 New Relic, Inc. All rights reserved
Est. 20 mins
Lab: Chart Challenge
Add these charts to a dashboard!
Use DemotronV2 account and WebPortal application:
• How many live visitors are on my site right now? • Show a distribution (histogram) of Transaction
response times
uniqueCount(session) AS 'Site Visitors'
histogram(duration, 0.5, 30)
• Application throughput grouped by Transaction Name
• Use the multiple functions to show how the front end
FACET name and back end performance compare right now (past
10 mins) ?
• Which response codes are we seeing?
average (duration), average(backendDuration)
FACET HttpResponseCode
• You have added a custom attribute to your
• Average response time grouped by Transaction Name Transaction event type in the WebPortal app to store
shopping cart total value:
FACET name
PurchasedCartGrandTotal
• Show percentile breakdowns of Transaction response
times • Show the total shopping cart value in the past 60 min
percentile(duration, 5, 50, 95) sum(PurchasedCartGrandTotal)
© 2022 New Relic, Inc. All rights reserved
Thank you.
[email protected]© 2022 New Relic, Inc. All rights reserved