-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
67 lines (55 loc) · 1.65 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
locals {
alarm_topic_arn = var.alarm_topic_arn != null ? var.alarm_topic_arn : "arn:aws:sns:${module.this.aws_region}:${module.this.aws_account_id}:${module.this.environment}-alarms"
}
module "cloudwatch_label" {
source = "justtrackio/label/null"
version = "0.26.0"
delimiter = "/"
label_order = var.label_orders.cloudwatch
context = module.this.context
}
resource "aws_cloudwatch_metric_alarm" "default" {
count = module.this.enabled ? 1 : 0
alarm_description = var.alarm_description
alarm_name = "${module.this.id}-${var.consumer_name}-success-rate"
datapoints_to_alarm = var.datapoints_to_alarm
comparison_operator = "LessThanThreshold"
evaluation_periods = var.evaluation_periods
threshold = var.threshold
treat_missing_data = "notBreaching"
metric_query {
id = "messages"
return_data = false
metric {
dimensions = {
Consumer = var.consumer_name
}
metric_name = "ProcessedCount"
namespace = module.cloudwatch_label.id
period = var.period
stat = "Sum"
}
}
metric_query {
id = "errors"
return_data = false
metric {
metric_name = "Error"
dimensions = {
Consumer = var.consumer_name
}
namespace = module.cloudwatch_label.id
period = var.period
stat = "Sum"
}
}
metric_query {
expression = "IF(messages == 0 OR errors == 0, 100, 100-100*(errors/messages))"
id = "e1"
label = "success rate"
return_data = true
}
alarm_actions = [local.alarm_topic_arn]
ok_actions = [local.alarm_topic_arn]
tags = module.this.tags
}