Helpful NRQL Queries - newrelic/observability-as-code GitHub Wiki

Logs

Query New Relic Logs

In this case, the query looks for custom Insights events within a specific time range. The logs were sent as custom events during Atlantis runs.

SELECT message FROM Log WHERE organization = 'Alerting' and repository='ace-terraform-atlantis' and project='eu-production_' and pr=7 SINCE '2020-10-09 15:30:00 UTC' UNTIL '2020-10-09 18:20:58 UTC' LIMIT 1000

NRQL alert condition equivalencies and examples

APM conditions

# Throughput (requests per minute)
SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName = 'application'

# Response time
SELECT average(duration) FROM Transaction WHERE appName = 'application'

# Response time (95th percentile)
SELECT percentile(duration, 95) FROM Transaction WHERE appName = 'application'

# Error rate (errors per minute)
SELECT rate(count(*), 1 minute) FROM Transaction WHERE error IS true AND appName = 'application'

# Browser response time
SELECT average(duration) from PageView WHERE appName = 'application'

# Mobile crashes
SELECT count(*) from MobileCrash where appName = 'application'

# JVM heap utilization
SELECT average(newrelic.timeslice.value) from Metric where appName = 'application' and metricTimesliceName = 'Memory/Heap/Utilization' timeseries

Infra conditions

# CPU usage
SELECT average(cpuPercent) FROM SystemSample WHERE host = 'hostname'

# Free memory
SELECT average(memoryFreePercent) FROM SystemSample where host = 'hostname'

# RDS CPU usage (requires a configured AWS cloud integration)
SELECT average(provider.cpuUtilization.Average) from DatastoreSample where dataSourceName = 'RDS' and aws.arn = 'arn:aws:rds:...'

# Redis keypace misses per second (requires the Redis infra integration)
SELECT average(db.keyspaceMissesPerSecond) from RedisSample where entityName = 'entity'

# Postgresql connection count (requires the Postgres infra integration)
SELECT average(db.connections) from PostgresqlDatabaseSample where entityGuid = 'entity'

Synthetics conditions

# Synthetics check duration
SELECT average(duration) FROM SyntheticCheck where monitorName = 'monitor'

# Synthetics errors
SELECT * FROM SyntheticCheck where monitorName = 'monitor' and error IS NOT NULL

# Multi-location synthetics errors
SELECT uniqueCount(location) FROM SyntheticCheck where monitorName = 'monitor' and error IS NOT NULL timeseries