Skip to content

Instantly share code, notes, and snippets.

@hardware
Created July 29, 2015 10:17
Show Gist options
  • Save hardware/3010353afe9b5165e95a to your computer and use it in GitHub Desktop.
Save hardware/3010353afe9b5165e95a to your computer and use it in GitHub Desktop.
// cron.js
// [...]
if( newRelicEvents.length > 0 )
newrelic.submitEvents( newRelicEvents, next );
res.send('PROCESSING REQUESTS COMPLETED !');
// [...]
----------------------------------------------------------------------------------------------------------------
// newrelicApi.js
// [...]
exports.submitEvents = function( events, next ) {
request({
uri:'https://insights-collector.newrelic.com/v1/accounts/' + process.env.NEW_RELIC_ACCOUNT + '/events',
method:'POST',
headers: {
'X-Insert-Key': process.env.NEW_RELIC_API_KEY,
'Content-Type': 'application/json'
},
json:true,
body:events
}, function( err, response, body ) {
if( err || response.statusCode != 200 ) {
next( new Error("NEWRELIC API - Submitting events failed") );
return;
}
});
};
// [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment