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

Why don't I get any metric for a given time period?

metrics
api

#1

Today I deployed a simple app to check out how Newrelic works and I am able to make REST API calls for metrics like requests_per_minute.However since I want the data for a particular time range, I specify the appropriate date and time for which I want the data.However for such scenarios, it returns value as 0.

Below is my curl command

curl -X GET 'https://api.newrelic.com/v2/applications/*********/metrics/data.xml' \
>      -H 'X-Api-Key:***************************************************' -i \
>      -d'names[]=CPU/User+Time&from=2018-04-04T11:00:00+00:00&to=2018-04-05T1:00:00+00:00&period=1800'

Below is my JSON response

<?xml version="1.0" encoding="UTF-8"?>
<metric_data_response>
  <metric_data>
    <from>2018-04-04T11:00:00+00:00</from>
    <to>2018-04-05T01:00:00+00:00</to>
    <metrics_not_found/>
    <metrics_found>
      <metrics_found>CPU/User Time</metrics_found>
    </metrics_found>
    <metrics>
      <metric>
        <name>CPU/User Time</name>
        <timeslices>
          <timeslice>
            <from>2018-04-04T11:00:00+00:00</from>
            <to>2018-04-04T11:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T11:30:00+00:00</from>
            <to>2018-04-04T12:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T12:00:00+00:00</from>
            <to>2018-04-04T12:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T12:30:00+00:00</from>
            <to>2018-04-04T13:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T13:00:00+00:00</from>
            <to>2018-04-04T13:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T13:30:00+00:00</from>
            <to>2018-04-04T14:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T14:00:00+00:00</from>
            <to>2018-04-04T14:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T14:30:00+00:00</from>
            <to>2018-04-04T15:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T15:00:00+00:00</from>
            <to>2018-04-04T15:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T15:30:00+00:00</from>
            <to>2018-04-04T16:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T16:00:00+00:00</from>
            <to>2018-04-04T16:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T16:30:00+00:00</from>
            <to>2018-04-04T17:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T17:00:00+00:00</from>
            <to>2018-04-04T17:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T17:30:00+00:00</from>
            <to>2018-04-04T18:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T18:00:00+00:00</from>
            <to>2018-04-04T18:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T18:30:00+00:00</from>
            <to>2018-04-04T19:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T19:00:00+00:00</from>
            <to>2018-04-04T19:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T19:30:00+00:00</from>
            <to>2018-04-04T20:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T20:00:00+00:00</from>
            <to>2018-04-04T20:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T20:30:00+00:00</from>
            <to>2018-04-04T21:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T21:00:00+00:00</from>
            <to>2018-04-04T21:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T21:30:00+00:00</from>
            <to>2018-04-04T22:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T22:00:00+00:00</from>
            <to>2018-04-04T22:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T22:30:00+00:00</from>
            <to>2018-04-04T23:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T23:00:00+00:00</from>
            <to>2018-04-04T23:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-04T23:30:00+00:00</from>
            <to>2018-04-05T00:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-05T00:00:00+00:00</from>
            <to>2018-04-05T00:30:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
          <timeslice>
            <from>2018-04-05T00:30:00+00:00</from>
            <to>2018-04-05T01:00:00+00:00</to>
            <values>
              <total_time>0</total_time>
              <average_time>0</average_time>
              <percent>0</percent>
            </values>
          </timeslice>
        </timeslices>
      </metric>
    </metrics>
  </metric_data>
</metric_data_response>

Below is the visualization of the data I receive in newrelic

As you can see indeed I got some data between April 4 11:00 PM and April 5 1:00 AM.Then why do I get empty data when I request through curl?


#2

Hi @Souvik - try changing the from and to values to unix timestamps with the milliseconds.


#3

Seems to me like @stefan_garnham has you on the right track, @Souvik! Let us know if you were able to try this and if you are closer to a solution now! :blush:


#4

Hi,

Facing the exactly the same problem, like souvik above.

All CPU/User+Time the values returned are 0 as below (though in the App dashboard chart indicates values)

https://rpm.newrelic.com/api/explore/applications/metric_data?application_id=157275271&names[]=CPU/User+Time&raw=false&values[]=percent

“name”: “CPU/User+Time”,
“timeslices”: [
{
“from”: “2019-12-03T12:56:00+00:00”,
“to”: “2019-12-03T12:57:00+00:00”,
“values”: {
“percent”: 0
}
},
{
“from”: “2019-12-03T12:57:00+00:00”,
“to”: “2019-12-03T12:58:00+00:00”,
“values”: {
“percent”: 0
}
},
{
“from”: “2019-12-03T12:58:00+00:00”,
“to”: “2019-12-03T12:59:00+00:00”,
“values”: {
“percent”: 0
}

Tried using unixtimestamp is milliseconds here :

https://rpm.newrelic.com/api/explore/applications/metric_data?application_id=157275271&names[]=CPU/User+Time&raw=false&values[]=percent&to=1575379035000&from=1575378835000

Its returning :
{
“error”: {
“title”: “invalid parameter: from”
}
}

An early resolution / solution will be highly appreciated


#5

Hello,

Though it didn’t work from API Explorer, it works from terminal ! It returns values in that case


#6

Hey @force.focus1 - that is odd - I just ran the following curl command:

curl -X GET 'https://api.newrelic.com/v2/applications/43192210/metrics/data.json' \
     -H 'X-Api-Key:myApiKey' -i \
     -G -d 'names[]=CPU/User+Time&from=2019-12-04T10:32:00+00:00&to=2019-12-04T10:33:00+00:00' 

Which returns the results:

{"metric_data":{"from":"2019-12-04T10:32:00+00:00","to":"2019-12-04T10:33:00+00:00","metrics_not_found":[],"metrics_found":["CPU/User Time"],"metrics":[{"name":"CPU/User Time","timeslices":[{"from":"2019-12-04T10:32:00+00:00","to":"2019-12-04T10:33:00+00:00","values":{"total_time":1120,"average_time":140,"percent":1.87}}]}]}}%

And from the API Explorer - I ran similar and got the same results:

Results:

 "metrics": [
      {
        "name": "CPU/User Time",
        "timeslices": [
          {
            "from": "2019-12-04T10:32:00+00:00",
            "to": "2019-12-04T10:33:00+00:00",
            "values": {
              "total_time": 1120,
              "average_time": 140,
              "percent": 1.87
            }
          }
        ]

I see that you were able to get some success from the Terminal, but not the API explorer - are you using the same API Key in both tests? And, can you confirm (perhaps by screenshot) how you have set the To and From variables in the API explorer?


#7

Thanks for the reply. Yes. Still we dont get any value from API explorer (both with or without ‘From’ & ‘To’ time stamp values) . SCreenshots enclosed.

However all is well from terminal curl, with same API key (with or without ‘From’ & ‘To’) . Also our python code also pulls metrics fine

The only confusing bit was the Api Explorer. Hopefully it helps some one facing this issue.


#8

Hey @force.focus1 - with your permission, I’d like to try out the API Explorer with your details to check what may be going on returning you 0’s.

If you are ok with that, could you DM me privately with an API key you are using? As well as the specific terminal command you are running?