diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md new file mode 100644 index 0000000..029ce14 --- /dev/null +++ b/databases/mongodb/README.md @@ -0,0 +1,81 @@ +AWS MongoDB Service DataDog monitors +========================================== + +Link to integration documentation : + +[https://docs.datadoghq.com/integrations/mongo/](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. + + +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 | `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 new file mode 100644 index 0000000..b698157 --- /dev/null +++ b/databases/mongodb/inputs.tf @@ -0,0 +1,25 @@ +# Global Terraform +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 15 +} + +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 = "*" +} diff --git a/databases/mongodb/monitors-mongo.tf b/databases/mongodb/monitors-mongo.tf new file mode 100644 index 0000000..03b55b8 --- /dev/null +++ b/databases/mongodb/monitors-mongo.tf @@ -0,0 +1,31 @@ +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.environment}] Member down in the replica set" + message = "${var.message}" + + query = <