Custom metrics allow you to report any metric that passes through your code. For example, with New Relic APM's Go monitoring, you can create custom metrics to time a component of your app that may not captured by default. Once you capture a custom metric, you can:
- Unify your monitoring inside New Relic through the New Relic Insights Metric Explorer.
- Use the New Relic REST API to programmatically retrieve and use custom metric data outside of the New Relic UI.
- Create custom metric alert conditions to notify you or your team when your custom metric exceeds specific values.
Create a custom metric
Instantiate your application by running the following:
cfg := newrelic.NewConfig("Your App Name", mustGetEnv("NEW_RELIC_LICENSE_KEY")) cfg.Logger = newrelic.NewDebugLogger(os.Stdout) var err error app, err = newrelic.NewApplication(cfg)
After instantiating your app, create a custom metric with the following code:
app.RecordCustomMetric( "CustomMetricName", //name of your metric 132, //time in ms );
RecordCustomMetric's first parameter is a string that names your custom metric.
RecordCustomMetricmethod will automatically prepend the string
Custom/to your metric name. This means the above code will generate a metric named
RecordCustomMetric's second parameter is the time, in milliseconds, that you want to record for your custom transaction. This means the above code will produce a metric of .132 seconds in New Relic's systems.
Name a custom metric
Carefully consider how you name your custom metrics. If your program creates too many uniquely-named metrics, you may end up with a metric grouping issue (MGI).
MGIs occur when the granularity of metric names is too fine, resulting in hundreds or thousands of different metric names. One common cause of MGIs is relying on the full URL name for metric naming in web transactions. A few major code paths may generate many different full URL paths to unique documents, articles, page, etc. If the unique element of the URL path is included in the metric name, each of these common paths will have its own unique metric name. If metric grouping issues occur, follow the troubleshooting procedures.
For more help
Additional documentation resources include: