Syntax
Java
NewRelic.setUserId(string $userId)
Kotlin
NewRelic.recordMetric( name: String, category: String, count: Int, totalValue: Double, exclusiveValue: Double, countUnit: MetricUnit, valueUnit: MetricUnit)NewRelic.recordMetric(name: String?, category: String?, value: Double = 1.0)
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.
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 theMetricCategory
enum.Parameters
Parameter
Type
Description
$name
string
Required. The desired 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.
count
int
Required. The number of times the metric was recorded.
totalValue
double
Required. The total value of the metric.
exclusiveValue
double
Required. The exclusive value of the recording; for example, if the total value contains measurements accounted for elsewhere.
countUnit
MetricUnit
Required. Unit of measurement for the metric count, including
PERCENT
,BYTES
,SECONDS
,BYTES_PER_SECOND
, orOPERATIONS
.valueUnit
MetricUnit
Required. Unit of measurement for the metric value, including
PERCENT
,BYTES
,SECONDS
,BYTES_PER_SECOND
, orOPERATIONS
.Examples
Here's an example of creating simple custom metrics:
Java
NewRelic.recordMetric("Custom Metric Name","MyCategory", 1.0);NewRelic.recordMetric("Login Auth Metric", "Network", 1.0);
Kotlin
NewRelic.recordMetric("Custom Metric Name","MyCategory", 1.0)NewRelic.recordMetric("Login Auth Metric", "Network", 1.0)
Here's an example of creating a custom metric for agent start:
Java
NewRelic.recordMetric("Agent start", "Lifecycle");
Kotlin
NewRelic.recordMetric("Agent start", "Lifecycle")
Here's an example of the same metric above, but with elapsed time value added:
Java
NewRelic.recordMetric("Agent start", "Lifecycle", 10.11f);
Kotlin
NewRelic.recordMetric("Agent start", "Lifecycle", 10.11)
Here's an example of the same metric above, but with five counts of elapsed time, exclusive time, and a unit value parameter:
Java
NewRelic.recordMetric("Agent start", "Lifecycle", 5, 10.11, 1.23, MetricUnit.OPERATIONS, MetricUnit.SECONDS);
Kotlin
NewRelic.recordMetric("Agent start", "Lifecycle", 5, 10.11, 1.23, MetricUnit.OPERATIONS, MetricUnit.SECONDS)
Syntax
Objective-c
[NewRelic recordMetricWithName:(NSString *)name category:(NSString *)category value:(NSNumber *)value];
Swift
NewRelic.recordMetric(withName: String!, category: String!, value: NSNumber!)
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 .
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 theMetricCategory
enum.Parameters
Parameter
Type
Description
name
NSString
Required. The desired name for the custom metric.
category
NSString
Required. The metric category name, either custom or using a predefined metric category.
value
NSNumber
Required. The value of the metric.
Examples
Objective-C
Here's an example of creating a metric in milliseconds:
[NewRelic recordMetricWithName:(NSString *)@"My Important Metric" category:(NSString *)@"Important Metrics" value:(NSNumber *)145.67];
Swift
Here's an example of creating a metric in milliseconds:
NewRelic.recordMetric(withName: "My Important Metric", category: "Important Metrics", value: 145.67)
Syntax
recordMetric(options: { name: string; category: string; value?: number; countUnit?: string; valueUnit?: string; }) => void
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
NewRelicCapacitorPlugin.recordMetric({ name: "CapacitorMetricName", category: "CapacitorMetricCategory",});NewRelicCapacitorPlugin.recordMetric({ name: "CapacitorMetricName2", category: "CapacitorMetricCategory2", value: 25,});NewRelicCapacitorPlugin.recordMetric({ name: "CapacitorMetricName3", category: "CapacitorMetricCategory3", value: 30, countUnit: NREnums.MetricUnit.SECONDS, valueUnit: NREnums.MetricUnit.OPERATIONS,});
Syntax
recordMetric(name: string, category: string, value?: number, countUnit?: string, valueUnit?: string): void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
NewRelic.recordMetric('CordovaCustomMetricName', 'CordovaCustomMetricCategory');NewRelic.recordMetric('CordovaCustomMetricName', 'CordovaCustomMetricCategory', 12);NewRelic.recordMetric('CordovaCustomMetricName', 'CordovaCustomMetricCategory', 13, 'PERCENT', 'SECONDS');
Syntax
RecordMetric(string name, string category) : void;RecordMetric(string name, string category, double value) : void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
CrossNewRelic.Current.RecordMetric("Agent start", "Lifecycle");CrossNewRelic.Current.RecordMetric("Login Auth Metric", "Network", 78.9);
Syntax
recordMetric(name: string, category: string, value?: number, countUnit?: string, valueUnit?: string): void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
NewrelicMobile.instance.recordMetric("testMetric", "Test Champ",value: 12.0);NewrelicMobile.instance.recordMetric("testMetric1", "TestChamp12",value: 10,valueUnit: MetricUnit.BYTES,countUnit: MetricUnit.PERCENT);
Syntax
recordMetric(name: string, category: string, value?: number, countUnit?: string, valueUnit?: string): void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
NewRelic.recordMetric('RNCustomMetricName', 'RNCustomMetricCategory');NewRelic.recordMetric('RNCustomMetricName', 'RNCustomMetricCategory', 12);NewRelic.recordMetric('RNCustomMetricName', 'RNCustomMetricCategory', 13, NewRelic.MetricUnit.PERCENT, NewRelic.MetricUnit.SECONDS);
Syntax
RecordMetricWithName(string name, string category) : void;RecordMetricWithName(string name, string category, double value) : void;RecordMetricWithName(string name, string category, double value, MetricUnit countUnit, MetricUnit valueUnit) : void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
NewRelicAgent.RecordMetricWithName('UnityCustomMetricName', 'UnityCustomMetricCategory');NewRelicAgent.RecordMetricWithName('UnityCustomMetricName', 'UnityCustomMetricCategory', 12);NewRelicAgent.RecordMetricWithName('UnityCustomMetricName', 'UnityCustomMetricCategory', 13, NewRelicAgent.MetricUnit.PERCENT, NewRelicAgent.MetricUnit.SECONDS);
Syntax
RecordMetric(string name, string category) : void;RecordMetric(string name, string category, double value) : void;RecordMetric(string name, string category, double value, MetricUnit countUnit, MetricUnit valueUnit) : void;
Description
Records custom metrics (arbitrary numerical data), where countUnit
is the measurement unit of the metric count and valueUnit
is the measurement unit for the metric value. If you use countUnit
or valueUnit
, then you must set all three: value
, countUnit
, and valueUnit
.
Supported measurements for countUnit
and valueUnit
are:
PERCENT
BYTES
SECONDS
BYTES_PER_SECOND
OPERATIONS
Parameters
Parameter
Type
Description
name
string
Required. The desired name for the custom metric.
category
string
Required. The metric category name, either custom or using a predefined metric category.
value
number
Required. The value of the metric.
countUnit
string
Required. The unit of measurement for the count.
valueUnit
string
Required. The unit of measurement for the count.
Example
CrossNewRelicClient.Current.RecordMetric("Agent start", "Lifecycle");CrossNewRelicClient.Current.RecordMetric("Login Auth Metric", "Network", 78.9);CrossNewRelicClient.Current.RecordMetric("Request Metric", "Network", 20, MetricUnit.SECONDS, MetricUnit.OPERATIONS);