Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

anotherrandomtestpackage

newrelic18LicenseRef-LICENSE2.1.2

A module for generating metrics from V8.

newrelic, gc, metrics, stats, gc-stats, gc stats, gc metrics, native-metrics, native metrics

readme

Native Metrics for New Relic Node Agent

This module provides hooks into the native layer of Node to provide metrics for the New Relic Node Agent. It gathers information that isn't available at the JS layer about the V8 virtual machine and the process health. It comes packaged with the New Relic Agent v2, and there is nothing that needs to be done. For Agent v1 you need only to install the module alongside newrelic.

Installation

npm install --save @newrelic/native-metrics

Note that this is a native module and thus must be compiled to function. Pre-built binaries are provided for Linux servers running supported versions of Node. If you are not using Linux or not using a supported version of Node, you will need to have a compiler installed on the machine where this is to be deployed. See node-gyp for more information on compiling native addons.

If you prepare and package deployments on one machine and install them on another, the two machines must have the same operating system and architecture. If they are not, you will need to re-build the native module after deploying in order to get the correct binaries.

During installation, the module will first attempt build from source on the target machine. If that fails, it will attempt to download a pre-built binary for your system. You can disable the download attempt by passing the flag --no-download during installation.

$ npm install @newrelic/native-metrics --no-download

Usage

var getMetricEmitter = require('@newrelic/native-metrics')

var emitter = getMetricEmitter()
if (emitter.gcEnabled) {
  emitter.on('gc', (gc) => console.log(gc.type + ': ' + gc.duration))
}
if (emitter.usageEnabled) {
  emitter.on('usage', (usage) => console.log(usage))
}
if (emitter.loopEnabled) {
  setInterval(() => {
    var loopMetrics = emitter.getLoopMetrics()
    console.log("Loop time:", loopMetrics.loop)
    console.log("IO wait time:", loopMetrics.ioWait)
  }, 1000)
}

The metric emitter keeps a referenced timer running for its periodic sampling events. For a graceful shutdown of the process call NativeMetricEmitter#unbind.

getMetricEmitter().unbind() // Process will now close gracefully.

If you would like to change the period of the sampling, simply unbind and then call NativeMetricEmitter#bind with the new period.

var emitter = getMetricEmitter({timeout: 15000})
emitter.unbind()
emitter.bind(10000) // Samples will now fire once every 10 seconds.

License

The New Relic native metrics module is free-to-use, proprietary software. Please see the full license (found in LICENSE) for details on its license and the licenses of its dependencies.

changelog

v2.1.2 (2017-09-26):

  • Metric timers no longer hold the process open.

Thanks to @samshull for the contribution!

v2.1.1 (2017-04-03):

  • Fixed build error on Windows thanks to Maximilian Haupt (@0x7f).

  • Added C++-layer unit testing using gtest.

  • Updated readme with correct installation for the New Relic Agent v1.

v2.1.0 (2017-02-06):

  • Added an event loop CPU usage metric.

    The module will now report round trip CPU usage metrics for Node's event loop. This metric can be read off with nativeMetrics.getLoopMetrics() and will represent the amount of CPU time per tick of the event loop.

v2.0.2 (2017-01-19):

  • Removed pre-compiling binaries using the node-pre-gyp module.

    Previously we provided pre-compiled binaries for certain platforms and versions of Node. However, this caused issues for customers using shrinkwrapping. In order to support shrinkwrapping as well as all versions of Node and npm that our customers use, we have decided to remove this feature. This means that in order to use this module, users now need to have a compiler on the machine where it is being installed. See [node-gyp] (https://www.npmjs.com/package/node-gyp#installation) for more information on compiling native addons.

v2.0.0 (2017-01-04):

  • Removed support for Node 0.10.

    The segfault-handler dependency no longer compiles on Node 0.10 in our tests.

  • The node-pre-gyp module is now a bundled dependency.

    Previously it was installed using a preinstall script, which was causing an issue with shrinkwrapping parent projects. Thanks to Robert Rossman (@Alaneor) for the contribution!

  • Added License section to the Readme file.

v1.0.0 (2016-12-07):

  • General release. No code changes from v0.1.1.

v0.1.1 (2016-12-05):

  • Added guard against binding GC events more than once.

  • Removed OS X from Travis to temporarily get around extremely long builds. Added script to run tests locally across multiple versions of Node.

  • Added test for checking licenses of dependencies.

v0.1.0 (2016-11-29):

  • Added gc event with duration and type of garbage collection.
  • Added usage event with current and diff of resource usage stats.