Search code examples
node.jsprometheusmetricsnewrelic

Recording custom dimensional metrics in New Relic


I’m looking for a way to record custom metrics with multiple dimensions using the node.js new-relic agent. From what I see, the API for custom metrics includes only a name and a value.

Is it possible to add labels to a metric so it can be queried according to multiple dimensions? For example, when I record metrics with Prometheus for my caching system, I add labels like:

  • server name
  • cache entry name
  • tenant ID
  • web API route

This allows me to aggregate my data according to different labels for different KPI dashboards (by tenant, by web API, etc).

Is this possible directly with New Relic? (I’m not asking about New Relic Prometheus integration)

It seems odd that the API is so simplistic when New Relic clearly supports dimensional metrics.


Solution

  • APM generally records non-dimensional metrics which are called metric timeslice data. I don't know the underlying reason for the difference, but I suspect it is simply due to the fact APM was New Relic's first product and dimensional metrics likely weren't implemented at the time. I haven't confirmed, but recordMetric() probably uses timeslice metrics.

    There are two main ways around this:

    1. APM transactions are dimensional. If the metrics are transaction-specific you can instead call newrelic.addCustomAttribute('key1', 'value1') multiple times to attach dimensions to the transaction. You can then query using NRQL. For example: FROM Transaction SELECT * WHERE key1 = 'value1' FACET key2.
    2. Call the metrics API directly. This lets you send dimensional metrics which will not be attached to the application, though of course one of the attributes can be the app name. It is then similarly queryable through NRQL: FROM Metric SELECT * WHERE key1 = 'value1' FACET key2.