Syntax
NewRelic.recordMetric(string $name, string $category)NewRelic.recordMetric(string $name, string $category, double $value)NewRelic.recordMetric(string $name, string $category, int $count, double $totalValue, double $exclusiveValue)NewRelic.recordMetric(string $name, string $category, int $count, double $totalValue, double $exclusiveValue, MetricUnit $countUnit, MetricUnit $valueUnit)
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.
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 more information, see the Android SDK API usage guide.
Parameters
This call accepts four sets of parameters.
Parameter | Description |
---|---|
| |
string | Required. The desired name for the custom metric. |
string | Required. The metric category name, either custom or using a predefined metric category. |
| |
string | Required. The desired name for the custom metric. |
string | Required. The metric category name, either custom or using a predefined metric category. |
double | Required. The value of the metric. |
| |
string | Required. The desired name for the custom metric. |
string | Required. The metric category name, either custom or using a predefined metric category. |
double | Required. The value of the metric. |
int | Required. The number of times the event has happened. |
double | Required. The total value of the recording. |
double | Required. The exclusive value of the recording; for example, if the total value contains measurements accounted for elsewhere. |
| |
string | Required. The desired name for the custom metric. |
string | Required. The metric category name, either custom or using a predefined metric category. |
double | Required. The value of the metric. |
int | Required. The number of times the event has happened. |
double | Required. The total value of the recording. |
double | Required. The exclusive value of the recording; for example, if the total value contains measurements accounted for elsewhere. |
MetricUnit | Required. Unit of measurement for the metric count, including |
MetricUnit | Required. Unit of measurement for the metric value, including |
Examples
Simple custom metric
Examples of creating custom metrics:
NewRelic.recordMetric("Custom Metric Name","MyCategory", 1.0);NewRelic.recordMetric("Login Auth Metric", "Network", 1.0);
Metric with optional attributes
An example of creating a custom metric for agent start:
NewRelic.recordMetric("Agent start", "Lifecycle");
Same metric with elapsed time value added:
NewRelic.recordMetric("Agent start", "Lifecycle", 10.11f);
With two counts of elapsed time and exclusive time:
NewRelic.recordMetric("Agent Start", "lifecycle", 2, 10.11, 1.23)
With five counts of elapsed time, exclusive time, and a unit value parameter:
NewRelic.recordMetric("Agent start", "Lifecycle", 5, 10.11, 1.23, MetricUnit.OPERATIONS, MetricUnit.SECONDS);