• /
  • Log in
  • Free account

recordMetric (iOS SDK API)

Syntax

NewRelic recordMetricWithName:(NSString *)name category:(NSString *)category value:(NSNumber *)value];
NewRelic.recordMetric(withName: 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 mobile monitoring.

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.

Examples

Objective-C

Method:

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

Example (metrics in milliseconds):

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

Swift

Method:

NewRelic.recordMetric(withName: String!, category: String!, value: NSNumber!)

Example (metrics in milliseconds):

NewRelic.recordMetric(withName: "My Important Metric", category: "Important Metrics", value: 145.67)
Create issueEdit page
Copyright © 2022 New Relic Inc.