Giter Club home page Giter Club logo

terraform-aws-cloudwatch-alarms's Introduction

Terraform AWS Cloudwatch Alarms

Terraform module creates Cloudwatch Alarm on AWS for monitoriing AWS services.

Terraform Licence


We eat, drink, sleep and most importantly love DevOps. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy Bigger problems are always solved by breaking them into smaller manageable problems. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller connected yet manageable pieces within the infrastructure.

This module is basically combination of Terraform open source and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.

We have fifty plus terraform modules. A few of them are comepleted and are available for open source usage while a few others are in progress.

Prerequisites

This module has a few dependencies:

Examples

IMPORTANT: Since the master branch used in source varies based on new modifications, we suggest that you use the release versions here.

Here are some examples of how you can use this module in your inventory structure:

Basic Example

    module "alarm" {
      source                    = "clouddrove/cloudwatch-alarms/aws"
      version                   = "0.15.0"
      name                      = "alarm"
      environment               = "test"
      label_order               = ["name", "environment"]
      alarm_name                = "cpu-alarm"
      comparison_operator       = "LessThanThreshold"
      evaluation_periods        = 2
      metric_name               = "CPUUtilization"
      namespace                 = "AWS/EC2"
      period                    = "60"
      statistic                 = "Average"
      threshold                 = "40"
      alarm_description         = "This metric monitors ec2 cpu utilization"
      alarm_actions             = ["arn:aws:sns:eu-west-1:xxxxxxxxxxx:test"]
      actions_enabled           = true
      insufficient_data_actions = []
      ok_actions                = []
      dimensions                = {
                    instance_id = "i-xxxxxxxxxxxxx"
      }
  }

Anomaly Example

    module "alarm" {
      source                    = "clouddrove/cloudwatch-alarms/aws"
      version                   = "0.15.0"
      name                      = "alarm"
      environment               = "test"
      label_order               = ["name", "environment"]
      alarm_name                = "cpu-alarm"
      comparison_operator       = "GreaterThanUpperThreshold"
      evaluation_periods        = 2
      threshold_metric_id       = "e1"
      query_expressions         = [{
        id          = "e1"
        expression  = "ANOMALY_DETECTION_BAND(m1)"
        label       = "CPUUtilization (Expected)"
        return_data = "true"
      }]
      query_metrics             = [{
        id          = "m1"
        return_data = "true"
        metric_name = "CPUUtilization"
        namespace   = "AWS/EC2"
        period      = "120"
        stat        = "Average"
        unit        = "Count"
        dimensions  = {
          InstanceId = module.ec2.instance_id[0]
        }
      }]
      alarm_description         = "This metric monitors ec2 cpu utilization"
      alarm_actions             = []
      actions_enabled           = true
      insufficient_data_actions = []
      ok_actions                = []
  }

Epression Example

    module "alarm" {
      source                    = "clouddrove/cloudwatch-alarms/aws"
      version                   = "0.15.0"
      name                      = "alarm"
      environment               = "test"
      label_order               = ["name", "environment"]
      expression_enabled        = true
      alarm_name                = "cpu-alarm"
      comparison_operator       = "GreaterThanUpperThreshold"
      evaluation_periods        = 2
      threshold                 = 40
      query_expressions         = [{
        id          = "e1"
        expression  = "ANOMALY_DETECTION_BAND(m1)"
        label       = "CPUUtilization (Expected)"
        return_data = "true"
      }]
      query_metrics             = [{
        id          = "m1"
        return_data = "true"
        metric_name = "CPUUtilization"
        namespace   = "AWS/EC2"
        period      = "120"
        stat        = "Average"
        unit        = "Count"
        dimensions  = {
          InstanceId = module.ec2.instance_id[0]
        }
      }]
      alarm_description         = "This metric monitors ec2 cpu utilization"
      alarm_actions             = []
      actions_enabled           = true
      insufficient_data_actions = []
      ok_actions                = []
  }

Inputs

Name Description Type Default Required
actions_enabled Indicates whether or not actions should be executed during any changes to the alarm's state. bool true no
alarm_actions The list of actions to execute when this alarm transitions into an ALARM state from any other state. list(any) [] no
alarm_description The description for the alarm. string "" no
alarm_name The descriptive name for the alarm. string n/a yes
comparison_operator The arithmetic operation to use when comparing the specified Statistic and Threshold. string n/a yes
dimensions Dimensions for metrics. map {} no
enabled Enable alarm. bool true no
environment Environment (e.g. prod, dev, staging). string "" no
evaluation_periods The number of periods over which data is compared to the specified threshold. number n/a yes
expression_enabled Enable alarm with expression. bool false no
instance_id The instance ID. string "" no
insufficient_data_actions The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. list(any) [] no
label_order Label order, e.g. name,application. list(any) [] no
managedby ManagedBy, eg 'CloudDrove'. string "[email protected]" no
metric_name The name for the alarm's associated metric. string "CPUUtilization" no
name Name (e.g. app or cluster). string "" no
namespace The namespace for the alarm's associated metric. string "AWS/EC2" no
ok_actions The list of actions to execute when this alarm transitions into an OK state from any other state. list(any) [] no
period The period in seconds over which the specified statistic is applied. number 120 no
query_expressions values for metric query expression. list
[
{
"expression": "ANOMALY_DETECTION_BAND(m1)",
"id": "e1",
"label": "CPUUtilization (Expected)",
"return_data": "true"
}
]
no
query_metrics values for metric query metrics. list
[
{
"dimensions": {
"InstanceId": "i-abc123"
},
"id": "m1",
"metric_name": "CPUUtilization",
"namespace": "AWS/EC2",
"period": "120",
"return_data": "true",
"stat": "Average",
"unit": "Count"
}
]
no
repository Terraform current module repo string "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms" no
statistic The statistic to apply to the alarm's associated metric. string "Average" no
threshold The value against which the specified statistic is compared. number 40 no
threshold_metric_id If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function. string "" no

Outputs

Name Description
arn The ARN of the cloudwatch metric alarm.
id The ID of the health check.
tags A mapping of tags to assign to the resource.

Testing

In this module testing is performed with terratest and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a GO environment in your system.

You need to run the following command in the testing folder:

  go test -run Test

Feedback

If you come accross a bug or have any feedback, please log it in our issue tracker, or feel free to drop us an email at [email protected].

If you have found it worth your time, go ahead and give us a ★ on our GitHub!

About us

At CloudDrove, we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.

We are The Cloud Experts!


We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.

terraform-aws-cloudwatch-alarms's People

Contributors

yadavprakash avatar anmolnagpal avatar dhyanio avatar sohanyadav avatar omsharma07 avatar clouddrove-ci avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.