135 lines
3.5 KiB
HCL
135 lines
3.5 KiB
HCL
resource "aws_ssm_association" "InstallCwAgent" {
|
|
name = "AWS-ConfigureAWSPackage"
|
|
association_name = "CwAgentInstall"
|
|
schedule_expression = "cron(0 00 01 ? * * *)"
|
|
max_concurrency = 10
|
|
parameters = {
|
|
name = "AmazonCloudWatchAgent"
|
|
action = "Install"
|
|
installationType = "Uninstall and reinstall"
|
|
additionalArguments = "{}"
|
|
}
|
|
targets {
|
|
key = "InstanceIds"
|
|
values = ["*"]
|
|
}
|
|
}
|
|
|
|
resource "aws_ssm_association" "ConfigCwAgent" {
|
|
name = "AmazonCloudWatch-ManageAgent"
|
|
association_name = "CwAgentConfiguration"
|
|
schedule_expression = "cron(0 00 02 ? * * *)"
|
|
max_concurrency = 10
|
|
parameters = {
|
|
action = "configure"
|
|
optionalConfigurationLocation = "AmazonCloudWatch-linux"
|
|
optionalConfigurationSource = "ssm"
|
|
mode = "ec2"
|
|
optionalRestart = "yes"
|
|
}
|
|
targets {
|
|
key = "InstanceIds"
|
|
values = ["*"]
|
|
}
|
|
}
|
|
|
|
resource "aws_ssm_parameter" "CwAgentConfigLinux" {
|
|
name = "AmazonCloudWatch-linux"
|
|
description = "Cloudwatch agent Standard config for Linux"
|
|
type = "String"
|
|
value = local.CwAgentLinuxConfig
|
|
}
|
|
|
|
locals {
|
|
CwAgentLinuxConfig = jsonencode(
|
|
{
|
|
"agent" : {
|
|
"metrics_collection_interval" : 60,
|
|
"run_as_user" : "root"
|
|
},
|
|
"metrics" : {
|
|
"aggregation_dimensions" : [
|
|
[
|
|
"InstanceId"
|
|
]
|
|
],
|
|
"append_dimensions" : {
|
|
"AutoScalingGroupName" : "$${aws:AutoScalingGroupName}",
|
|
"ImageId" : "$${aws:ImageId}",
|
|
"InstanceId" : "$${aws:InstanceId}",
|
|
"InstanceType" : "$${aws:InstanceType}"
|
|
},
|
|
"metrics_collected" : {
|
|
"cpu" : {
|
|
"measurement" : [
|
|
"cpu_usage_idle",
|
|
"cpu_usage_iowait",
|
|
"cpu_usage_user",
|
|
"cpu_usage_system"
|
|
],
|
|
"metrics_collection_interval" : 60,
|
|
"resources" : [
|
|
"*"
|
|
],
|
|
"totalcpu" : false
|
|
},
|
|
"disk" : {
|
|
"measurement" : [
|
|
"used_percent",
|
|
"inodes_free"
|
|
],
|
|
"metrics_collection_interval" : 60,
|
|
"resources" : [
|
|
"*"
|
|
],
|
|
"ignore_file_system_types" : [
|
|
"devtmpfs",
|
|
"overlay",
|
|
"sysfs",
|
|
"tmpfs"
|
|
]
|
|
},
|
|
"diskio" : {
|
|
"measurement" : [
|
|
"io_time"
|
|
],
|
|
"metrics_collection_interval" : 60,
|
|
"resources" : [
|
|
"*"
|
|
]
|
|
},
|
|
"mem" : {
|
|
"measurement" : [
|
|
"mem_used_percent"
|
|
],
|
|
"metrics_collection_interval" : 60
|
|
},
|
|
"statsd" : {
|
|
"metrics_aggregation_interval" : 60,
|
|
"metrics_collection_interval" : 10,
|
|
"service_address" : ":8125"
|
|
},
|
|
"swap" : {
|
|
"measurement" : [
|
|
"swap_used_percent"
|
|
],
|
|
"metrics_collection_interval" : 60
|
|
},
|
|
"net": {
|
|
"measurement": [
|
|
"net_err_in",
|
|
"net_err_out"
|
|
],
|
|
"metrics_collection_interval": 60
|
|
},
|
|
"processes": {
|
|
"measurement": [
|
|
"processes_total"
|
|
],
|
|
"metrics_collection_interval": 60
|
|
}
|
|
}
|
|
}
|
|
}
|
|
)
|
|
} |