This content originally appeared on DEV Community and was authored by TD!
In today's data-driven world, the ability to query and analyze data efficiently is crucial for businesses to make informed decisions. This is where New Relic Query Language (NRQL), a powerful tool designed to help you retrieve and understand data from your applications, hosts, and business activities comes in. Though this is my first post about New Relic since I became a New Relic Full Stack Observability Practitioner, I'll be writing a series of articles to explain the New Relic Query Language which I find really interesting.
In this post we'll explore what NRQL is, how it works, and some practical examples to get you started. In subsequent posts, the examples might be complex than it is here.
What is NRQL?
NRQL, short for New Relic Query Language, is a query language similar to ANSI SQL. It allows you to query detailed New Relic data to gain insights into your applications, hosts, and business-critical activities. With NRQL, you can create custom charts, answer specific questions for troubleshooting or business analysis, set up alerts, and make API queries using New Relic's NerdGraph API.
Getting Started with NRQL
To begin using NRQL, you'll need access to the New Relic platform. Click here. Here are some key places where you can run NRQL queries:
- Query Builder: Access the query builder within the New Relic platform to run and modify queries.
- NRQL Console: Run NRQL queries from anywhere within New Relic using the NRQL console.
- NRQL-based Alerts: Set up NRQL-based alerts to notify you of issues and help you address them promptly¹.
Basic NRQL Syntax
NRQL queries are structured similarly to SQL queries. Here's a basic example to get you started:
FROM Transaction
SELECT average(duration)
FACET appName
TIMESERIES auto
This query retrieves the average duration of transactions, grouped by application name, and displays the data over an automated timespan.
Practical Examples
Let's dive into some practical examples to see NRQL in action:
- Counting Unique Users:
SELECT uniqueCount(user)
FROM PageView
WHERE userAgentOS = 'Mac'
FACET countryCode
SINCE 1 day ago
LIMIT 20
This will appear on your Query Builder like:
This query counts the unique users accessing your application from Mac OS, grouped by country code, within the last day.
- Querying Multiple Data Sources:
SELECT count(*)
FROM Transaction, PageView
SINCE 3 days ago
This query returns the count of all APM transactions and browser events over the last three days. For this dashboard, there's currently no ongoing transaction
- Returning Multiple Columns:
SELECT function(attribute), function(attribute)
FROM Transaction
This query returns multiple columns from the dataset by separating the aggregator arguments with a comma².
Tips and Tricks
- Explore Existing Dashboards: Click "View query" on any existing dashboard chart to see the underlying NRQL query. Modify and customize the query to suit your needs².
- Play with Your Data: Don't be afraid to experiment with your data. You won't break anything by tinkering with NRQL queries².
NRQL is a versatile and powerful tool that empowers you to unlock the full potential of your data. Whether you're troubleshooting issues, analyzing business metrics, or setting up alerts, NRQL provides the flexibility and precision you need to make data-driven decisions. You can also enroll for the New Relic University learning paths and become an Observability Practitioner. Click here if you're interested.
Proudly an Observability Practitioner.
This content originally appeared on DEV Community and was authored by TD!
TD! | Sciencx (2024-07-23T13:25:46+00:00) NRQL – New Relic Query Language. Retrieved from https://www.scien.cx/2024/07/23/nrql-new-relic-query-language/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.