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

NRQL documentation and query


#1

I’m just learning my way around NRQL but I don’t know how to go about formulating a query. I’ve read the docs, I know SQL, where I’m having a problem is knowing WHAT to query. As in SELECT * FROM ? Where can I find a list of the possible FROMs?

The specific issue: I currently have 2 servers with apps running that are being monitored. If I do SELECT * from SystemSample LIMIT 1, I only get a response for one server. I need LIMIT 2 to see both. Bigger limits just give me more responses for each server.

I’m eventually going to have many more servers, and that will be an unknown and likely a changing number. What I want to do is either 1) get a list of servers, then get the responses for each server, or 2) get ONLY the most recent entry for all servers.


#2

Hi, @knights1: You can find information about the default event types here: https://docs.newrelic.com/docs/insights/insights-data-sources/default-data/insights-default-data-other-new-relic-products.

The LIMIT clause specifies the maximum number of rows you want in the result. As you have discovered, if you specify LIMIT 1, you will receive 1 row. If you specify LIMIT 2000 (the maximum), you will get as many rows as are available, up to 2000.

It sounds like you want to FACET (group) your data by host name. For example, to see the average memory usage per server, you would do this:

SELECT average(memoryUsedBytes) FROM SystemSample FACET hostname

To get only the most recent entry, you may use the latest() function:

SELECT latest(memoryUsedBytes) FROM SystemSample FACET hostname

#3

Thank you, that almost gets me where I need to be. If I try to select more than one entry, they all have the same key:

SELECT latest(cpuSystemPercent), latest(diskFreePercent) FROM SystemSample FACET hostname

results in:

    "facets": [
    {
        "name": "knt-linux-2",
        "results": [
            {
                "latest": 0.603255569934845
            },
            {
                "latest": 83.64466094970703
            }
        ]
    },
    {
        "name": "content-docs",
        "results": [
            {
                "latest": 0.30120548605918884
            },
            {
                "latest": 80.73169708251953
            }
        ]
    }
],

I also tried using AS:

SELECT latest(cpuSystemPercent) AS 'csp', latest(diskFreePercent) AS 'dfp' FROM SystemSample FACET hostname

But that produced the same results.

How can I get those to show different labels? Or am I going to have to rely on the order they’re returned?


#4

The AS clause works if you display the result in a chart:

Unfortunately, I do not know of a way to change the label in the JSON response.


#5

I’m doing this with an API call - not sure if I can get it in a chart form. Since I’m using it programatically, I’m pretty much stuck with the API.

I don’t suppose you know if I can at least rely on the order in the response to be the same as the order in the request?


#6

I don’t know for sure, but if I were a betting man, I would wager that you can. :slight_smile: