Custom metrics let you record arbitrary performance data via an API call (for example, timing or computer resource data). Then use the query builder to create charts and track that metric. You can use custom metrics to unify your monitoring inside New Relic.
Collecting too many metrics can impact the performance of your application and your New Relic agent. To avoid data problems, keep the total number of unique custom metrics under 2000.
Metric names identify specific data values tracked by New Relic. When using the New Relic Ruby agent's API to track custom metrics, it's important to consider your metric naming and how the values will aggregate.
A custom metric name consists of the prefix
Custom/, the class or category name, and a label, each separated with a slash mark
Custom/<category>/<name> (for example,
Record custom metrics
increment_metric are thread safe.
record_metric should be used to record an event-based metric, usually associated with a particular duration.
metric_name must be a String following standard metric naming rules.
value will usually be a Numeric, but may also be a Hash.
value is a numeric value, it should represent the magnitude of a measurement associated with an event, such as the duration for a particular method call.
value is a Hash, it must contain
:sum_of_squares keys, all with Numeric values. This form is useful if you wish to aggregate metrics on your own and report them periodically (for example, from a background thread). The provided stats will be aggregated with any previously collected values for the same metric. The names of the hash keys have been chosen to match the names of the keys used by the platform API.
increment_metric should be used to update a metric that acts as a simple counter. The count of the selected metric will be incremented by the specified amount.
Example custom metric
Here is an example that shows how you might use metrics to track currency flowing through a site:
def checkout() amount = compute_cart_total # computes the amount to charge the customer
charge_customer(amount) ... endend
For more information about how data aggregates over time, see Stat aggregation policy.
View custom metrics
To view these custom metrics, use the query builder to search metrics, create customizable charts, and add those charts to dashboards.