newrelic_custom_metric(string $metric_name, float $value)
Add a custom metric (in milliseconds) to time a component of your app not captured by default.

Description

Record custom metrics that aren't captured by default by the PHP agent.

Then you can:

  • Use the Metric Explorer in Insights to search for your custom metrics, create customizable charts, and add them to Insights dashboards.
  • Use the New Relic REST API to programatically retrieve and use custom metric data outside of the New Relic UI.
  • Create custom metric alerts to notify you or your team when your custom metric exceeds specific values.

Parameters

Parameter Description

$metric_name

string

Required. Name your custom metrics with a Custom/ prefix (for example, Custom/MyMetric). This helps the UI organize your custom metrics in one place, and it makes them easily findable via the Metric Explorer.

$value

float

Required. Records timing in milliseconds. For example: a value of 4 is stored as .004 seconds in New Relic's systems.

If the value is NaN, Infinity, denorm or negative zero, the behavior of this function is undefined. New Relic may discard 1 or more bits of precision (ULPs) from the given value.

Return value(s)

Returns true if the metric was added successfully.

Example(s)

Record a 100 millisecond response time

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
	    newrelic_add_custom_metric("Custom/custom-metric-name", 100.00);
    }
}