Skip to content

Commit

Permalink
add CloudWatch and SNS (#57)
Browse files Browse the repository at this point in the history
* add CloudWatch and SNS

* rename as federation

* rename dashboard item

* fix sns name in alarm_action

* update changelog
  • Loading branch information
lingwm authored and pradeepbhadani committed Apr 10, 2019
1 parent 15109ad commit ac7a520
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2019-04-09

### Added
- Add CloudWatch and SNS - see [#57](https://github.com/ExpediaGroup/apiary-federation/pull/57).


## [1.1.0] - 2019-04-05

### Added
Expand Down
86 changes: 86 additions & 0 deletions cloudwatch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,89 @@ resource "aws_cloudwatch_log_group" "waggledance_ecs" {
name = "${local.instance_alias}"
tags = "${var.tags}"
}

resource "aws_cloudwatch_dashboard" "apiary_federation" {
dashboard_name = "${local.instance_alias}-${var.aws_region}"

dashboard_body = <<EOF
{
"widgets": [
{
"type":"metric",
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "CPUUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ]
],
"period":300,
"stat":"Average",
"region":"${var.aws_region}",
"title":"WaggleDance ECS CPU Utilization"
}
},
{
"type":"metric",
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ]
],
"period":300,
"stat":"Average",
"region":"${var.aws_region}",
"title":"WaggleDance ECS Memory Utilization"
}
}
]
}
EOF
}


locals {
alerts = [
{
alarm_name = "${local.instance_alias}-cpu"
namespace = "AWS/ECS"
metric_name = "CPUUtilization"
threshold = "80"
},
{
alarm_name = "${local.instance_alias}-memory"
namespace = "AWS/ECS"
metric_name = "MemoryUtilization"
threshold = "70"
}
]

dimensions = [
{
ClusterName = "${local.instance_alias}"
ServiceName = "${local.instance_alias}-service"
},
{
ClusterName = "${local.instance_alias}"
ServiceName = "${local.instance_alias}-service"
}
]
}


resource "aws_cloudwatch_metric_alarm" "waggledance_alert" {
count = "${length(local.alerts)}"
alarm_name = "${lookup(local.alerts[count.index],"alarm_name")}"
comparison_operator = "${lookup(local.alerts[count.index],"comparison_operator","GreaterThanOrEqualToThreshold")}"
metric_name = "${lookup(local.alerts[count.index],"metric_name")}"
namespace = "${lookup(local.alerts[count.index],"namespace")}"
period = "${lookup(local.alerts[count.index],"period","120")}"
evaluation_periods = "${lookup(local.alerts[count.index],"evaluation_periods","2")}"
statistic = "Average"
threshold = "${lookup(local.alerts[count.index],"threshold")}"

#alarm_description = ""
insufficient_data_actions = []
dimensions = "${local.dimensions[count.index]}"
alarm_actions = ["${aws_sns_topic.apiary_federation_ops_sns.arn}"]
}
3 changes: 3 additions & 0 deletions sns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_sns_topic" "apiary_federation_ops_sns" {
name = "${local.instance_alias}-operational-events"
}

0 comments on commit ac7a520

Please sign in to comment.