Merge branch 'MON-39-new_relic' into 'master'

MON-39 New Relic monitors: Apdex Score Ratio, Error Rate and No Data.

See merge request claranet/pt-monitoring/projects/datadog/terraform/monitors!98
This commit is contained in:
Quentin Manfroi 2019-08-29 13:55:41 +02:00
commit e567752f2c
6 changed files with 278 additions and 0 deletions

View File

@ -196,6 +196,8 @@ The `//` is very important, it's a terraform specific syntax used to separate gi
- [apache](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/apache/) - [apache](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/apache/)
- [nginx](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/nginx/) - [nginx](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/nginx/)
- [php-fpm](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/php-fpm/) - [php-fpm](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/php-fpm/)
- [saas](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/saas/)
- [new-relic](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/saas/new-relic/)
- [system](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/) - [system](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/)
- [generic](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/generic/) - [generic](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/generic/)
- [unreachable](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/unreachable/) - [unreachable](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/unreachable/)

60
saas/new-relic/README.md Normal file
View File

@ -0,0 +1,60 @@
# SAAS NEW-RELIC DataDog monitors
## How to use this module
```
module "datadog-monitors-saas-new-relic" {
source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//saas/new-relic?ref={revision}"
environment = var.environment
message = module.datadog-message-alerting.alerting-message
}
```
## Purpose
Creates DataDog monitors with the following checks:
- New Relic Apdex score ratio
- New Relic Error rate
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| app\_apdex\_score\_enabled | Flag to enable APP Apdex Score monitor | string | `"true"` | no |
| app\_apdex\_score\_extra\_tags | Extra tags for New Relic APP Apdex Score monitor | list(string) | `[]` | no |
| app\_apdex\_score\_message | Custom message for the APP Apdex Score monitor | string | `""` | no |
| app\_apdex\_score\_threshold\_critical | APP Apdex Score critical threshold | string | `"0.25"` | no |
| app\_apdex\_score\_threshold\_warning | APP Apdex Score warning threshold | string | `"0.5"` | no |
| app\_apdex\_score\_time\_aggregator | Time aggregator for the APP Apdex Score monitor | string | `"avg"` | no |
| app\_apdex\_score\_timeframe | Timeframe for the APP Apdex Score monitor | string | `"last_15m"` | no |
| app\_error\_rate\_enabled | Flag to enable APP Error Rate monitor | string | `"true"` | no |
| app\_error\_rate\_extra\_tags | Extra tags for New Relic APP Error Rate monitor | list(string) | `[]` | no |
| app\_error\_rate\_message | Custom message for the APP Error Rate monitor | string | `""` | no |
| app\_error\_rate\_threshold\_critical | APP Error Rate critical threshold | string | `"5"` | no |
| app\_error\_rate\_threshold\_warning | APP Error Rate warning threshold | string | `"1"` | no |
| app\_error\_rate\_time\_aggregator | Time aggregator for the APP Error Rate monitor | string | `"min"` | no |
| app\_error\_rate\_timeframe | Timeframe for the APP Error Rate monitor | string | `"last_5m"` | no |
| environment | Architecture Environment | string | n/a | yes |
| evaluation\_delay | Delay in seconds for the metric evaluation | string | `"900"` | no |
| filter\_tags\_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `"*"` | no |
| filter\_tags\_custom\_excluded | Tags excluded for custom filtering when filter_tags_use_defaults is false | string | `""` | no |
| filter\_tags\_use\_defaults | Use default filter tags convention | string | `"true"` | no |
| message | Message sent when an alert is triggered | string | n/a | yes |
| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no |
| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no |
## Outputs
| Name | Description |
|------|-------------|
| app\_apdex\_score\_id | id for monitor app_apdex_score |
| app\_error\_rate\_id | id for monitor app_error_rate |
## Related documentation
* [Datadog New Relic integration](https://docs.datadoghq.com/integrations/new_relic/)

130
saas/new-relic/inputs.tf Normal file
View File

@ -0,0 +1,130 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = string
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 900
}
variable "new_host_delay" {
description = "Delay in seconds before monitor new resource"
default = 300
}
variable "prefix_slug" {
description = "Prefix string to prepend between brackets on every monitors names"
default = ""
}
variable "message" {
description = "Message sent when an alert is triggered"
}
variable "filter_tags_use_defaults" {
description = "Use default filter tags convention"
default = "true"
}
variable "filter_tags_custom" {
description = "Tags used for custom filtering when filter_tags_use_defaults is false"
default = "*"
}
variable "filter_tags_custom_excluded" {
description = "Tags excluded for custom filtering when filter_tags_use_defaults is false"
default = ""
}
#
# APP Error Rate
#
variable "app_error_rate_enabled" {
description = "Flag to enable APP Error Rate monitor"
type = string
default = "true"
}
variable "app_error_rate_message" {
description = "Custom message for the APP Error Rate monitor"
type = string
default = ""
}
variable "app_error_rate_time_aggregator" {
description = "Time aggregator for the APP Error Rate monitor"
type = string
default = "min"
}
variable "app_error_rate_timeframe" {
description = "Timeframe for the APP Error Rate monitor"
type = string
default = "last_5m"
}
variable "app_error_rate_threshold_warning" {
description = "APP Error Rate warning threshold"
type = string
default = 1
}
variable "app_error_rate_threshold_critical" {
description = "APP Error Rate critical threshold"
type = string
default = 5
}
variable "app_error_rate_extra_tags" {
description = "Extra tags for New Relic APP Error Rate monitor"
type = list(string)
default = []
}
#
# APP Apdex Score
#
variable "app_apdex_score_enabled" {
description = "Flag to enable APP Apdex Score monitor"
type = string
default = "true"
}
variable "app_apdex_score_message" {
description = "Custom message for the APP Apdex Score monitor"
type = string
default = ""
}
variable "app_apdex_score_time_aggregator" {
description = "Time aggregator for the APP Apdex Score monitor"
type = string
default = "avg"
}
variable "app_apdex_score_timeframe" {
description = "Timeframe for the APP Apdex Score monitor"
type = string
default = "last_15m"
}
variable "app_apdex_score_threshold_warning" {
description = "APP Apdex Score warning threshold"
type = string
default = 0.5
}
variable "app_apdex_score_threshold_critical" {
description = "APP Apdex Score critical threshold"
type = string
default = 0.25
}
variable "app_apdex_score_extra_tags" {
description = "Extra tags for New Relic APP Apdex Score monitor"
type = list(string)
default = []
}

View File

@ -0,0 +1,9 @@
module "filter-tags" {
source = "../../common/filter-tags"
environment = var.environment
resource = "new_relic"
filter_tags_use_defaults = var.filter_tags_use_defaults
filter_tags_custom = var.filter_tags_custom
filter_tags_custom_excluded = var.filter_tags_custom_excluded
}

View File

@ -0,0 +1,67 @@
resource "datadog_monitor" "app_error_rate" {
count = var.app_error_rate_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] New Relic Error rate {{#is_alert}}{{{comparator}}} {{threshold}}errs/min ({{value}}errs/min){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}errs/min ({{value}}errs/min){{/is_warning}}"
message = coalesce(var.app_error_rate_message, var.message)
type = "query alert"
query = <<EOQ
${var.app_error_rate_time_aggregator}(${var.app_error_rate_timeframe}):
avg:new_relic.errors.all.errors_per_minute${module.filter-tags.query_alert} by {application}
> ${var.app_error_rate_threshold_critical}
EOQ
thresholds = {
warning = var.app_error_rate_threshold_warning
critical = var.app_error_rate_threshold_critical
}
evaluation_delay = var.evaluation_delay
new_host_delay = var.new_host_delay
notify_no_data = false
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
tags = concat(["env:${var.environment}", "type:saas", "provider:new-relic", "resource:new-relic", "team:claranet", "created-by:terraform"], var.app_error_rate_extra_tags)
lifecycle {
ignore_changes = ["silenced"]
}
}
resource "datadog_monitor" "app_apdex_score" {
count = var.app_apdex_score_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] New Relic Apdex score ratio {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
message = coalesce(var.app_apdex_score_message, var.message)
type = "query alert"
query = <<EOQ
${var.app_apdex_score_time_aggregator}(${var.app_apdex_score_timeframe}):
avg:new_relic.apdex.score${module.filter-tags.query_alert} by {application}
< ${var.app_apdex_score_threshold_critical}
EOQ
thresholds = {
warning = var.app_apdex_score_threshold_warning
critical = var.app_apdex_score_threshold_critical
}
evaluation_delay = var.evaluation_delay
new_host_delay = var.new_host_delay
notify_no_data = false
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
tags = concat(["env:${var.environment}", "type:saas", "provider:new-relic", "resource:new-relic", "team:claranet", "created-by:terraform"], var.app_apdex_score_extra_tags)
lifecycle {
ignore_changes = ["silenced"]
}
}

10
saas/new-relic/outputs.tf Normal file
View File

@ -0,0 +1,10 @@
output "app_apdex_score_id" {
description = "id for monitor app_apdex_score"
value = datadog_monitor.app_apdex_score.*.id
}
output "app_error_rate_id" {
description = "id for monitor app_error_rate"
value = datadog_monitor.app_error_rate.*.id
}