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

How to add data point from remote json?


#1

Hi. This is a ‘can i do this questions’ and a request for pointers to docs for where to start.

On my api I have an endpoint that exposes a value (number). I would like to have NR pull that number in (eg: every 5 minutes) so I can alert on the number if it passes a certain value, as well as expose the latest value on an insights dashboard.

Can I do this? Or do I have to push the data into NR?

I feel like there should be a way to do this via synthetic, but unsure.

thanks


#2

Hi, @mahimod: Yes, you can do this with Synthetics.

  1. Create a Synthetics API Test to call your endpoint. The script below calls the quantum random number generator service provided by the Australian National University. It sends the returned value to Insights, and throws an exception if the value is 128 or greater:
    var assert = require('assert');

    $http.get('https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint8',
      // Callback
      function (err, response, body) {
        assert.equal(response.statusCode, 200, 'Expected a 200 OK response');
        var value = JSON.parse(body).data[0];
        $util.insights.set('returnedValue', value);
        assert.equal(value < 128, true, 'Expected value less than 128');
      }
    );
  1. Create an alert condition to notify you if the Synthetics monitor fails;

  2. Query the custom attribute and display it on an Insights dashboard:

    SELECT latest(`custom.returnedValue`) AS 'Latest Value' 
    FROM SyntheticCheck WHERE monitorName = 'Random Number API Test'