record_custom_metric

For general information on how the Python agent API calls relate to each other, see the API guide.

newrelic.agent.record_custom_metric(name, value, application=None)
Records a single custom metric.

Description

This call records a single custom metric. To record a set of metrics, see record_custom_metrics.

Parameters

Parameter Description

name

string

Required. Name of the metric.

There are no restrictions on naming formats, but New Relic recommends you use a Custom/ prefix for your custom metric names. This helps you differentiate custom metrics from default-monitored metrics in the New Relic UI, and also helps you troubleshoot if necessary.

value

int or dict

Required. The numeric value of the metric. Can be an integer, a float, or a dictionary of values. The possible fields for a dictionary are:

  • count
  • total
  • min
  • max
  • sum_of_squares

For explanations of these fields and some general usage tips, see the documentation for the New Relic Plugins custom metrics API.

application

application object

Optional. The application object corresponding to the app with which you want to associate the metrics. If the application is the default value of None, the agent records the custom metrics to the app associated with the current transaction. Thus, you should provide the application unless this method is used in code for a web transaction or background task.

Return value(s)

None.

Example(s)

Recording a custom metric using the application object

To record custom metrics from a distinct background thread or other code, you must pass the application object corresponding to the application to which the custom metrics are to be reported.

import newrelic.agent
application = newrelic.agent.application()

newrelic.agent.record_custom_metric('Custom/my_favorite_number', 42, application)

For more help

Recommendations for learning more: