• Log inStart now

Create metrics from other data types

Use New Relic's metrics API service to define rules for creating metrics from your other types of data, such as events, logs, or spans. Recommendation: Before you begin, review our requirements and tips for creating rules.

Create a metrics rule

To create a rule for creating metrics from events, logs, or spans:

  1. Construct the metrics rule using NRQL.
  2. Construct a NerdGraph (GraphQL format) API request that contains your NRQL rule.
  3. Create the metric by making the API request.

Once a metric is created, you can query and chart it using NRQL.

Step 1. Create NRQL query rule

The most important part of creating a metrics rule is constructing the NRQL query that defines the metric for your data from events, logs, or spans. You can create up to 10 metrics with a single NRQL query by following this procedure:

  1. Using New Relic's NRQL interface, construct a query for the metric you want to create. For example:

    FROM ProcessSample SELECT average(ioTotalReadBytes)
    WHERE nr.entityType = 'HOST'
  2. Edit the query to use one of the three available metric types:

    • summary: Use if the query's function is min, max, sum, count, or average.

    • uniqueCount: Use if the query's function is uniqueCount.

    • distribution: Use if the query's function is percentile or histogram.

      This example query uses average, so use summary:

      FROM ProcessSample SELECT summary(ioTotalReadBytes) 
      WHERE nr.entityType = 'HOST'

      This example query uses count on a non-numeric field:

      FROM ProcessSample SELECT count(hostname)
      WHERE hostname LIKE '%prod%'

      For summary on a non-numeric field use summary(1):

      FROM ProcessSample SELECT summary(1) 
      WHERE hostname LIKE '%prod%'

      Tip

      For more detailed information on using these metric types in rules, see Creating metric rules: requirements and tips.

  3. Decide on the attributes you want to attach to the metric, following the limits on the cardinality of unique metric-name/attribute-value combinations.

    Recommendation: Run a separate query to ensure this count isn't over 50,000 for a 24-hour window. For example:

    FROM ProcessSample
    SELECT uniqueCount(awsRegion, awsAvailabilityZone, commandName)
    WHERE nr.entityType = 'HOST'
    SINCE 1 DAY AGO
  4. To be able to aggregate and filter your metrics, add the attributes you want to attach to the metric using the FACET clause. For example:

    FROM ProcessSample
    SELECT summary(ioTotalReadBytes) WHERE nr.entityType = 'HOST' 
    FACET awsRegion, awsAvailabilityZone, commandName
  5. Set the name of the metric using the AS function. For example:

    FROM ProcessSample SELECT summary(ioTotalReadBytes) AS 'io.totalread.bytes'
    WHERE nr.entityType = 'HOST' FACET awsRegion, awsAvailabilityZone, commandName

Once your NRQL rule is complete, use it to create the API request.

Step 2. Create API request

After you build the NRQL rule to convert data from events, logs, or spans to metrics, continue with building the API request. You can use our NerdGraph API tool to explore the data structure and to construct and make your request.

To check that the rule was created correctly, you can run a query to return that rule using its ID. For tips on querying the metrics you've created, see Query and chart your metrics.

Step 3. Create a metrics rule with API request

When your API request is ready, you can use the NerdGraph API to make the request, which will create the metrics.

Query and chart your metrics

After you create a metrics rule to convert data for your events, logs, or spans, you can view the new metric data in the New Relic UI. To view your data:

  1. Go to New Relic's NRQL query interface.

  2. Run the following query to see the name of all your metrics:

    SELECT uniques(metricName) FROM Metric
  3. Pick the metric of interest, then run the following query to see the available attributes:

    SELECT * FROM Metric where metricName = 'yourMetric'
  4. If you don't see expected data, follow the troubleshooting procedures.

The available NRQL aggregator functions depend on the metric type you created. Here are some examples.

Troubleshooting

If your NerdGraph call is not constructed correctly, you may receive a message like this:

Cannot parse the unexpected character "\u201C”

Verify the quotes in the NerdGraph call are not smart quotes (curly quotes). Our NerdGraph API only accepts straight quotes.

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.