RousselTMLEARNING

Observability

Automating New Relic and controlling costs

Managing New Relic as code and keeping the bill under control: NerdGraph API, newrelic CLI, newrelic/newrelic Terraform provider, deployment tracking from CI, measuring ingest per source, drop rules, sampling and governance of accounts and users.

1. NerdGraph and the CLI #

New Relic's GraphQL API.

NerdGraph #

New Relic as code

NerdGraph (https://api.newrelic.com/graphql, api.eu.newrelic.com in the EU) exposes almost everything: NRQL queries, entities and tags, dashboards, alerts, service levels, drop rules, users. The built-in explorer (NerdGraph API explorer) generates queries and documents the schema.

mutation {
  changeTrackingCreateDeployment(deployment: {
    entityGuid: "<application GUID>"
    version: "2026.11.23-1"
    user: "ci"
    description: "New checkout page"
  }) { deploymentId }
}

The newrelic CLI #

newrelic profile add --profile prod --apiKey $NEW_RELIC_API_KEY --accountId $NEW_RELIC_ACCOUNT_ID --region EU
newrelic entity search --name boutique
newrelic nrql query --query "SELECT count(*) FROM Transaction SINCE 1 hour ago"
newrelic install -n infrastructure-agent-installer,logs-integration

2. Terraform #

Observability as code.

A full example #

terraform {
  required_providers {
    newrelic = { source = "newrelic/newrelic", version = "~> 3.102" }
  }
}
provider "newrelic" {}   # NEW_RELIC_API_KEY, NEW_RELIC_ACCOUNT_ID, NEW_RELIC_REGION

resource "newrelic_alert_policy" "boutique" {
  name                = "Boutique - production"
  incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_one_dashboard" "boutique" {
  name        = "Boutique - overview"
  permissions = "public_read_only"
  page {
    name = "Service"
    widget_billboard {
      title  = "Apdex"
      row    = 1
      column = 1
      nrql_query { query = "SELECT apdex(duration, t: 0.5) FROM Transaction WHERE appName = 'boutique'" }
    }
  }
}
  • Main resources: newrelic_alert_policy, newrelic_nrql_alert_condition, newrelic_workflow, newrelic_notification_destination, newrelic_service_level, newrelic_one_dashboard, newrelic_synthetics_*, newrelic_nrql_drop_rule.
  • The newrelic_entity data source looks up an application GUID by name.
  • One module per service (policy, conditions, SLO, dashboard) gives every team the same baseline.
Best practice : Create alerts and SLOs in Terraform, and keep the UI for exploration: what runs in production must be reviewed and versioned.

3. Controlling costs #

Measure, then reduce.

Measuring #

Ingest volume
-- Ingest per data type over 30 days
SELECT sum(GigabytesIngested) FROM NrConsumption WHERE productLine = 'DataPlatform' FACET usageMetric SINCE 30 days ago
-- Estimated log volume per service
SELECT bytecountestimate() / 10e8 AS 'GB' FROM Log FACET service SINCE 1 day ago
-- Billable users
SELECT latest(userType) FROM NrUsage WHERE productLine = 'FullStackObservability' FACET userEmail SINCE 30 days ago

Reducing #

LeverEffect
NRQL drop rulesdrop DEBUG logs, health checks, bulky attributes
Filtering at sourcepattern in logging.d, OpenTelemetry Collector processors
Trace samplingagent settings, Infinite Tracing with retention rules
Events to metricskeep long trends without every event
Process samplesonly enable useful processes
UsersBasic by default, Core or Full platform only when needed
Watch out : A single application logging at DEBUG in production can multiply the bill: set an alert on daily consumption.

Commands to know #

Commands to know
  • newrelic nrql query --query "…" : run NRQL from the command line
  • newrelic entity search --name boutique : find an entity and its GUID
  • terraform plan && terraform apply : apply the New Relic configuration
  • SELECT bytecountestimate() FROM Log FACET service : log volume per service

Sources #

Checked in November 2026: New Relic evolves its platform continuously (UI, plans, limits); check the documentation before relying on a detail.

Related articles

New Relic: the observability platform at a glance

Discover New Relic: history, the unified platform and NRDB, MELT data types, entities and golden signals, acc…

New Relic APM: agents, OpenTelemetry and distributed traces

Instrumenting applications with New Relic: language agents, configuration, transactions and Apdex, distribute…

Infrastructure, logs and Kubernetes with New Relic

Monitoring servers, containers and Kubernetes with New Relic: infrastructure agent, on-host integrations, clo…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!