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.
These procedures have not bee tested with Rails version 7 or higher.
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,
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.
Here is an example that shows how you might use metrics to track currency flowing through a site:
class Cartdef checkout()amount = compute_cart_total # computes the amount to charge the customer::NewRelic::Agent.record_metric('Custom/Cart/charge_amount', amount)charge_customer(amount)...endend
For more information about how data aggregates over time, see Stat aggregation policy.
To view these custom metrics, use the query builder to search metrics, create customizable charts, and add those charts to dashboards.