UPD: refactored cw dimension detection
This commit is contained in:
parent
14ef1770c2
commit
d30103f29e
6
modules/ManagementGovernance/Monitoring.EC2/get-cwagent-dimensions.sh
Executable file
6
modules/ManagementGovernance/Monitoring.EC2/get-cwagent-dimensions.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
eval "$(jq -r '@sh "id=\(.input)"')"
|
||||||
|
|
||||||
|
aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \
|
||||||
|
--dimensions Name=InstanceId,Value=$id Name=path,Value=/ | \
|
||||||
|
jq '.Metrics[] | .Dimensions[] | {(.Name):(.Value)}' | jq -s 'add'
|
@ -149,12 +149,21 @@ resource "aws_cloudwatch_metric_alarm" "ec2-swap_free" {
|
|||||||
|
|
||||||
|
|
||||||
# get device dimension from cw metrics
|
# get device dimension from cw metrics
|
||||||
|
/*
|
||||||
data "external" "disk-device" {
|
data "external" "disk-device" {
|
||||||
program = ["bash", "${path.module}/get-cwagent-device.sh"]
|
program = ["bash", "${path.module}/get-cwagent-device.sh"]
|
||||||
query = {
|
query = {
|
||||||
input = var.ec2-instance-id
|
input = var.ec2-instance-id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
data "external" "cw-dimensions" {
|
||||||
|
program = ["bash", "${path.module}/get-cwagent-dimensions.sh"]
|
||||||
|
query = {
|
||||||
|
input = var.ec2-instance-id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_cloudwatch_metric_alarm" "ec2-disk_free" {
|
resource "aws_cloudwatch_metric_alarm" "ec2-disk_free" {
|
||||||
count = data.external.ec2-os.result.os == "Linux" ? 1 : 0
|
count = data.external.ec2-os.result.os == "Linux" ? 1 : 0
|
||||||
@ -171,6 +180,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_free" {
|
|||||||
actions_enabled = var.actions-enabled
|
actions_enabled = var.actions-enabled
|
||||||
alarm_actions = [var.sns-targets.alarm-actions-urgent]
|
alarm_actions = [var.sns-targets.alarm-actions-urgent]
|
||||||
ok_actions = [var.sns-targets.alarm-actions-urgent]
|
ok_actions = [var.sns-targets.alarm-actions-urgent]
|
||||||
|
dimensions = data.external.cw-dimensions.result
|
||||||
|
/*
|
||||||
dimensions = {
|
dimensions = {
|
||||||
InstanceId = var.ec2-instance-id
|
InstanceId = var.ec2-instance-id
|
||||||
ImageId = data.aws_instance.ec2-instance.ami
|
ImageId = data.aws_instance.ec2-instance.ami
|
||||||
@ -179,6 +190,7 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_free" {
|
|||||||
fstype = data.external.disk-device.result.fstype
|
fstype = data.external.disk-device.result.fstype
|
||||||
path = "/"
|
path = "/"
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
tags = var.default-tags
|
tags = var.default-tags
|
||||||
lifecycle {
|
lifecycle {
|
||||||
ignore_changes = [tags]
|
ignore_changes = [tags]
|
||||||
@ -201,6 +213,8 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_inodes_free" {
|
|||||||
actions_enabled = var.actions-enabled
|
actions_enabled = var.actions-enabled
|
||||||
alarm_actions = [var.sns-targets.alarm-actions-urgent]
|
alarm_actions = [var.sns-targets.alarm-actions-urgent]
|
||||||
ok_actions = [var.sns-targets.alarm-actions-urgent]
|
ok_actions = [var.sns-targets.alarm-actions-urgent]
|
||||||
|
dimensions = data.external.cw-dimensions.result
|
||||||
|
/*
|
||||||
dimensions = {
|
dimensions = {
|
||||||
InstanceId = var.ec2-instance-id
|
InstanceId = var.ec2-instance-id
|
||||||
ImageId = data.aws_instance.ec2-instance.ami
|
ImageId = data.aws_instance.ec2-instance.ami
|
||||||
@ -209,6 +223,7 @@ resource "aws_cloudwatch_metric_alarm" "ec2-disk_inodes_free" {
|
|||||||
fstype = data.external.disk-device.result.fstype
|
fstype = data.external.disk-device.result.fstype
|
||||||
path = "/"
|
path = "/"
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
tags = var.default-tags
|
tags = var.default-tags
|
||||||
lifecycle {
|
lifecycle {
|
||||||
ignore_changes = [tags]
|
ignore_changes = [tags]
|
||||||
|
Loading…
Reference in New Issue
Block a user