newrelic / terraform-provider-newrelic

Terraform provider for New Relic
https://registry.terraform.io/providers/newrelic/newrelic/latest/docs
Mozilla Public License 2.0
201 stars 245 forks source link

Document Equivalent NRQL for Current Alert Conditions #1031

Closed ntkach closed 3 years ago

ntkach commented 3 years ago

Feature Description

I see in the documentation for the terraform module you mention that basically the newrelic_alert_condition is being deprecated:

The newrelic_nrql_alert_condition resource is preferred for configuring alerts conditions. In most cases feature parity can be achieved with a NRQL query. Other condition types may be deprecated in the future and receive fewer product updates.

We really need some kind of documentation for converting something like the "Response Time (web) High" out of the box alerts into their equivalent in NRQL.

Describe Alternatives

I can't seem to find anything where NewRelic (or community) has provided something like this. The only alternative I can think of would be sticking with the "non-preferred" version indefinitely.

Additional context

I think people would be fine with converting their newrelic_alert_condition over to newrelic_nrql_alert_condition. However you need to give them some guidance. Surely the plain vanilla alert conditions that have existed for ages should be simple to replicate as NRQL versions.

sanderblue commented 3 years ago

Hi @ntkach, you bring up a valid point. We've compiled a list of helpful NRQL queries in hopes of facilitating this adjustment. Please see the extensive list below for more information. And please feel free to share additional query if you have any that seem useful to you.

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 = 'chi-prod-entity-store-dgxlhk2.nr-ops.net'

# 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

In the meantime, we'll see what we can come up with regard to official documentation for changing newrelic_alert_condition to an equivalent newrelic_nrql_alert_condition. 😎

jpvajda commented 3 years ago

@sanderblue Thanks for responding to this, could this be a guide on the developer site? Or it make a great discuss.newrelic.com post if it's not guide-worthy. I'm happy to post it to Discuss if you feel it will help the community.

jpvajda commented 3 years ago

@ctrombley let me know what you think of my question if you have a free moment.

ntkach commented 3 years ago

@sanderblue Thanks! That's an excellent example of what I was looking for!

jpvajda commented 3 years ago

@ntkach do you think this would make a useful Discuss post? I'm happy to post there if you feel others could benefit from this info.

casey-robertson commented 3 years ago

@ntkach do you think this would make a useful Discuss post? I'm happy to post there if you feel others could benefit from this info.

Yes it would!

jpvajda commented 3 years ago

https://discuss.newrelic.com/t/terraform-newrelic-nrql-alert-conditions-achieved-with-a-nrql-query/124548

zeitlerc commented 10 months ago

These suggestions work except that EXTRAPOLATE needs to be added on the end for high throughput applications. https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#extrapolate

toini commented 3 days ago

When we create APM alert conditions with newrelic_nrql_alert_condition instead of newrelic_alert_condition they do not appear in the "Alert conditions" section in the APM GUI. Can we make them appear there somehow? Or do we need to use the deprecated newrelic_alert_condition to make that happen?

image