Skip to main content

New Relic Insights

Latest Version: 1.0.0

This library wraps the New Relic Insights API. New Relic Insights allow you to quickly and easily track, analyze and create real-time dashboards around event-based data.

You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.

To include this library in your project, add

#require "NewRelicInsights.class.nut:1.0.0"

at the top of your agent code

Class Usage

Constructor: NewRelicInsights(accountNumber, apiKey[, platform])

To instantiate a new NewRelicInsights object, you will need your New Relic Insights account number and API key, both as strings. An optional third parameter can be supplied to indicate the platform (electricimp will be used if no platform is specified).

#require "NewRelicInsights.class.nut:1.0.0"

const ACCOUNT_NUMBER = "YOUR ACCCOUNT NUMBER";
const API_KEY = "YOUR API KEY";
insights <- NewRelicInsights(ACCOUNT_NUMBER, API_KEY);

Class Methods

sendEvent(eventType, data[, callback])

The sendEvent() method sends a new event to the Insights engine. If a callback is supplied (this is optional) the request will be made asynchronously and the callback will be executed upon completion. If no callback is supplied, the request will be made synchronously and the method will return a table with two keys: err and data. Examples of both can be seen below:

// Asynchronous request
device.on("temp", function(data) {
    local insightsData = {
        "ts" : data.timestamp,
        "temp" : data.temperature
    };

    // Send asynchronously
    insights.sendEvent("temperature", insightsData, function(err, result) {
        // If there was an issue, report it
        if (err != null) {
            server.error(err);
            return;
        }

        // Otherwise, log success
        server.log("Success");
    });
});
// Synchronous request
device.on("temp", function(data) {
    local insightData = {
        "ts" : data.timestamp,
        "temp" : data.temperature
    };

    // Send synchronously
    local result = insights.sendEvent("temperature", insightsData);

    // If there was an issue, report it
    if (result.err) {
        server.error(result.err)
        return;
    }

    // Otherwise, log success
    server.log("Success");
});

Release History

The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.

Version Source Code Notes
1.0.0 GitHub Initial release

License

The New Relic Insights library is licensed under the MIT License.