You can generate metric-type data from other types of data in New Relic, including events, logs, and spans. Metrics are aggregates of your data and are optimal for analyzing and monitoring trends over long time periods.
This document explains:
- Reasons to use this feature
- Available operations
- How to use our NerdGraph API tool to perform operations
Using metrics allows for more efficient data storage. This in turn allows you to query your data and build charts more easily. The difference between metrics and other types of data in New Relic is based on time. For more information, see Understand data types.
- Events, logs, spans: These types of data represent a single record at a specific moment in time. For example, you may have an event for every request to the system. This data is ideal for in-depth troubleshooting and analysis.
- Metrics: These provide an aggregated view of your events, logs, or spans. Metrics are better for showing trends over longer time ranges. For example, you can aggregate the total number of requests per service to one metric and then examine this information month over month.
Why use metrics?
Data aggregation and retention
Here's a video showing how to generate metric data from non-metric data (7:47 minutes):
To get started converting your data to metrics, create a rule.
To show, create, and delete rules for generating metrics from events, logs, or spans, use NerdGraph, our GraphQL-format API. Before performing any operation, we recommend reading Intro to NerdGraph and exploring your data with the GraphiQL API tool.
These operations fall under two basic request types:
- Mutations, which are operations that make changes to existing rules or settings (for example, creating a new metrics rule).
- Queries, for fetching existing data (for example, fetching existing metrics rules).
All operations are role-based in NerdGraph as the currently logged-in New Relic user.
Mutation operations for events to metrics, logs to metrics, or spans to metrics include:
Query operations include:
- Create the metrics operation's request with the required parameters.
- Go to api.newrelic.com/graphiql, and paste your query into the box.
- To execute the operation, press Play. Or, to get the cURL format, select Copy as cURL.)
- Validate the response in the response box.
- Optional: To verify that your rule-creation operation was performed successfully, run a list query for that rule ID.