From c4841850d86c84c994f8c8a243fd21d3cada2227 Mon Sep 17 00:00:00 2001 From: Ahmed Fourti Date: Fri, 1 Dec 2017 17:43:40 +0100 Subject: [PATCH 1/5] MON-92 Added MongoDB Monitor --- databases/mongodb/README.md | 48 +++++++++++++++++++++++++++++ databases/mongodb/inputs.tf | 1 + databases/mongodb/monitors-mongo.tf | 34 ++++++++++++++++++++ inputs.tf | 19 +++++++++++- 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 databases/mongodb/README.md create mode 120000 databases/mongodb/inputs.tf create mode 100644 databases/mongodb/monitors-mongo.tf diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md new file mode 100644 index 0000000..8407e2a --- /dev/null +++ b/databases/mongodb/README.md @@ -0,0 +1,48 @@ +###MongoDB Monitors + +Link to integration documentation : + +``https://docs.datadoghq.com/integrations/mongo/`` + +**Prepare your ReplicaSet** : + +Add a user to your ReplicaSet (on the primary instance) + + +``` +use admin +db.auth("admin", "admin-password") ## This is optional is you don't have any admin password +db.createUser({"user":"datadog", "pwd": "{{PASSWORD}}", "roles" : [ {role: 'read', db: 'admin' }, {role: 'clusterMonitor', db: 'admin'}, {role: 'read', db: 'local' }]}) +``` + +**Configure your Datadog agent** + +Add this file conf.d/mongo.yaml + +``` + +init_config: + +instances: + - server: mongodb://datadog:password@[MONGO_URI] + tags: + - mytag1 + - mytag2 + - server: mongodb://datadog:password@[MONGO_URI] + tags: + - mytag1 + - mytag2 +``` + +**Monitor ReplicaSet Health** + +Name: [environment] Replica Set heath for {{ replset_name }} + +This monitor will check the health of your ReplicaSet + +Metrics are : + +1: The replicaSet is OK +0: The replicaSet is KO + +This monitor will trigger an alert for each ReplicaSet. diff --git a/databases/mongodb/inputs.tf b/databases/mongodb/inputs.tf new file mode 120000 index 0000000..cdfc6c6 --- /dev/null +++ b/databases/mongodb/inputs.tf @@ -0,0 +1 @@ +../../inputs.tf \ No newline at end of file diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf new file mode 100644 index 0000000..7a0fdc9 --- /dev/null +++ b/databases/mongodb/monitors-mongo.tf @@ -0,0 +1,34 @@ +module "message" { + source = "../../common/alerting-message" + oncall_24x7 = "${var.hno_escalation_group}" + oncall_office_hours = "${var.ho_escalation_group}" +} + +resource "datadog_monitor" "Mongodb_ReplicaSet_State" { + name = "[${var.env}] Replica Set heath for {{ replset_name }}" + message = "${module.message.alerting-message}" + + query = < Date: Mon, 19 Feb 2018 17:24:12 +0100 Subject: [PATCH 2/5] MON-92 - Update PR by following recommendations --- databases/mongodb/README.md | 38 +++++++++++++++++++++++++++-- databases/mongodb/inputs.tf | 32 +++++++++++++++++++++++- databases/mongodb/monitors-mongo.tf | 35 +++++++++++++------------- inputs.tf | 18 -------------- 4 files changed, 85 insertions(+), 38 deletions(-) mode change 120000 => 100644 databases/mongodb/inputs.tf diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md index 8407e2a..0ee13b3 100644 --- a/databases/mongodb/README.md +++ b/databases/mongodb/README.md @@ -1,8 +1,10 @@ -###MongoDB Monitors +AWS MongoDB Service DataDog monitors +========================================== Link to integration documentation : -``https://docs.datadoghq.com/integrations/mongo/`` +[https://docs.datadoghq.com/integrations/mongo/](https://docs.datadoghq.com/integrations/mongo/) + **Prepare your ReplicaSet** : @@ -46,3 +48,35 @@ Metrics are : 0: The replicaSet is KO This monitor will trigger an alert for each ReplicaSet. + + +How to use this module +---------------------- + +``` +module "datadog-monitors-aws-mongodb" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//databases/mongodb?ref={revision}" + + message = "${module.datadog-message-alerting.alerting-message}" + environment = "${var.environment}" + +} +``` + +Purpose +------- + +Creates a DataDog monitors with the following checks : +* Mongodb ReplicaSet status + +Inputs +------ + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture Environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `600` | no | +| filter_tags_custom | Tags used 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 | - | yes | +| replica_status_critical | The ReplicaSet status is DOWN | string | `0` | no | diff --git a/databases/mongodb/inputs.tf b/databases/mongodb/inputs.tf deleted file mode 120000 index cdfc6c6..0000000 --- a/databases/mongodb/inputs.tf +++ /dev/null @@ -1 +0,0 @@ -../../inputs.tf \ No newline at end of file diff --git a/databases/mongodb/inputs.tf b/databases/mongodb/inputs.tf new file mode 100644 index 0000000..e5e1cc6 --- /dev/null +++ b/databases/mongodb/inputs.tf @@ -0,0 +1,31 @@ +# Global Terraform +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 600 +} + +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 = "*" +} + +##MongoDB +variable "replica_status_critical" { + description = "The ReplicaSet status is DOWN" + default = 0 +} diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf index 7a0fdc9..86d25cf 100644 --- a/databases/mongodb/monitors-mongo.tf +++ b/databases/mongodb/monitors-mongo.tf @@ -1,34 +1,35 @@ -module "message" { - source = "../../common/alerting-message" - oncall_24x7 = "${var.hno_escalation_group}" - oncall_office_hours = "${var.ho_escalation_group}" +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_monitoring_mongodb:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } } -resource "datadog_monitor" "Mongodb_ReplicaSet_State" { - name = "[${var.env}] Replica Set heath for {{ replset_name }}" - message = "${module.message.alerting-message}" +resource "datadog_monitor" "mongodb_replicaset_state" { + name = "[${var.environment}] Replica Set heath for {{ replset_name }}" + message = "${var.message}" query = < Date: Tue, 20 Feb 2018 11:06:27 +0100 Subject: [PATCH 3/5] MON-92 - Hardcode threshold --- databases/mongodb/README.md | 1 - databases/mongodb/inputs.tf | 6 ------ databases/mongodb/monitors-mongo.tf | 6 +----- inputs.tf | 1 + 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md index 0ee13b3..e2b12c9 100644 --- a/databases/mongodb/README.md +++ b/databases/mongodb/README.md @@ -79,4 +79,3 @@ Inputs | filter_tags_custom | Tags used 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 | - | yes | -| replica_status_critical | The ReplicaSet status is DOWN | string | `0` | no | diff --git a/databases/mongodb/inputs.tf b/databases/mongodb/inputs.tf index e5e1cc6..ff336dc 100644 --- a/databases/mongodb/inputs.tf +++ b/databases/mongodb/inputs.tf @@ -23,9 +23,3 @@ variable "filter_tags_custom" { description = "Tags used for custom filtering when filter_tags_use_defaults is false" default = "*" } - -##MongoDB -variable "replica_status_critical" { - description = "The ReplicaSet status is DOWN" - default = 0 -} diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf index 86d25cf..d436ffc 100644 --- a/databases/mongodb/monitors-mongo.tf +++ b/databases/mongodb/monitors-mongo.tf @@ -13,15 +13,11 @@ resource "datadog_monitor" "mongodb_replicaset_state" { query = < Date: Wed, 21 Feb 2018 14:38:52 +0100 Subject: [PATCH 4/5] MON-92 - Update monitor and inputs --- databases/mongodb/README.md | 2 +- databases/mongodb/inputs.tf | 2 +- databases/mongodb/monitors-mongo.tf | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md index e2b12c9..029ce14 100644 --- a/databases/mongodb/README.md +++ b/databases/mongodb/README.md @@ -75,7 +75,7 @@ Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | environment | Architecture Environment | string | - | yes | -| evaluation_delay | Delay in seconds for the metric evaluation | string | `600` | no | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `15` | no | | filter_tags_custom | Tags used 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 | - | yes | diff --git a/databases/mongodb/inputs.tf b/databases/mongodb/inputs.tf index ff336dc..b698157 100644 --- a/databases/mongodb/inputs.tf +++ b/databases/mongodb/inputs.tf @@ -7,7 +7,7 @@ variable "environment" { # Global DataDog variable "evaluation_delay" { description = "Delay in seconds for the metric evaluation" - default = 600 + default = 15 } variable "message" { diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf index d436ffc..74b1174 100644 --- a/databases/mongodb/monitors-mongo.tf +++ b/databases/mongodb/monitors-mongo.tf @@ -7,13 +7,13 @@ data "template_file" "filter" { } resource "datadog_monitor" "mongodb_replicaset_state" { - name = "[${var.environment}] Replica Set heath for {{ replset_name }}" + name = "[${var.environment}] Replica Set health" message = "${var.message}" query = < Date: Thu, 22 Feb 2018 11:05:09 +0100 Subject: [PATCH 5/5] MON-92 - Update monitor's name --- databases/mongodb/monitors-mongo.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf index 74b1174..03b55b8 100644 --- a/databases/mongodb/monitors-mongo.tf +++ b/databases/mongodb/monitors-mongo.tf @@ -7,7 +7,7 @@ data "template_file" "filter" { } resource "datadog_monitor" "mongodb_replicaset_state" { - name = "[${var.environment}] Replica Set health" + name = "[${var.environment}] Member down in the replica set" message = "${var.message}" query = <