recordMetric

NewRelic recordMetricWithName:(NSString *)name category:(NSString *)category value:(NSNumber *)value]; NewRelic.recordMetricWithName(name: String!, category: String!, value: NSNumber!)
Record custom metrics (arbitrary numerical data).

Requirements

Compatible with all agent versions.

Description

With this method, you can record arbitrary custom metrics to give more detail about app activity that is not tracked by New Relic automatically. The call accepts several sets of parameters for optional levels of detail.

This method will record a metric of the form Custom/[Category]/[Name], with a count of 1 and a total value equal to the value passed in. Multiple calls will aggregate the count and value according to standard metric aggregation rules for New Relic Mobile.

To get the most out of your metrics, follow these guidelines to create clear, concise metric names:

  • Use case and whitespace characters appropriate for display in the user interface. Metric names are rendered as-is.
  • Capitalize the metric name.
  • Avoid using the characters / ] [ | * when naming metrics.
  • Avoid multi-byte characters.

The category is also required; it is displayed in the UI and is useful for organizing custom metrics if you have many of them. It can be a custom category or it can be a predefined category using the MetricCategory enum.

To view your custom metrics, use Insights Metric Explorer to search metrics, create customizable charts, and add those charts to Insights dashboards.

For variations that accept additional arguments and give you more control over the metrics you record, see NewRelic.h. For more information about using this API, see the iOS SDK API usage guide.

Parameters

Parameter Description

$name

string

Required. The name for the custom metric.

$category

string

Required. The metric category name, either custom or using a predefined metric category.

Value

double

Required. The value of the metric.

Example(s)

Objective-C

Method:

[NewRelic recordMetricWithName:(NSString *)name 
  category:(NSString *)category 
    value:(NSNumber *)value];

Example:

[NewRelic recordMetricWithName:(NSString *)@"My Important Metric (in milliseconds)"
  category:(NSString *)@"Important Metrics" 
    value:(NSNumber *)145.67];

Swift

Method:

NewRelic.recordMetricWithName(name: String!, category: String!, value: NSNumber!)

Example:

NewRelic.recordMetricName(name: "My Important Metric (in milliseconds)", category: "Important Metrics", value: 145.67)

For more help

Recommendations for learning more: