From c916f917716b585a77f07b9f1f4bb4fa53a76204 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 12 Feb 2022 18:25:03 -0800 Subject: [PATCH] Delete CloudWatch --- packer/cloudwatch.json | 41 ---------- packer/provision.bash | 7 +- packer/web.pkr.hcl | 5 -- tf/cloudwatch.tf | 174 ----------------------------------------- tf/iam.tf | 58 -------------- tf/outputs.tf | 9 --- 6 files changed, 1 insertion(+), 293 deletions(-) delete mode 100644 packer/cloudwatch.json delete mode 100644 tf/cloudwatch.tf diff --git a/packer/cloudwatch.json b/packer/cloudwatch.json deleted file mode 100644 index 36ec712..0000000 --- a/packer/cloudwatch.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "agent": { - "metrics_collection_interval": 60, - "run_as_user": "root" - }, - "metrics": { - "append_dimensions": { - "ImageId": "${aws:ImageId}", - "InstanceId": "${aws:InstanceId}", - "InstanceType": "${aws:InstanceType}" - }, - "aggregation_dimensions": [ - ["RijuInstanceGroup"], - ["RijuInstanceGroup", "path"] - ], - "metrics_collected": { - "cpu": { - "append_dimensions": { - "RijuInstanceGroup": "Webserver" - }, - "measurement": ["usage_active"], - "metrics_collection_interval": 60 - }, - "disk": { - "append_dimensions": { - "RijuInstanceGroup": "Webserver" - }, - "measurement": ["used_percent"], - "metrics_collection_interval": 60, - "resources": ["/", "/mnt/riju"] - }, - "mem": { - "append_dimensions": { - "RijuInstanceGroup": "Webserver" - }, - "measurement": ["mem_used_percent"], - "metrics_collection_interval": 60 - } - } - } -} diff --git a/packer/provision.bash b/packer/provision.bash index 281fa01..a2655d6 100644 --- a/packer/provision.bash +++ b/packer/provision.bash @@ -44,16 +44,12 @@ sudo ./aws/install wget -nv https://s3.us-west-1.amazonaws.com/amazon-ssm-us-west-1/latest/debian_amd64/amazon-ssm-agent.deb -wget -nv https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -sudo apt-get install -y ./amazon-cloudwatch-agent.deb - sudo chown root:root \ - /tmp/cloudwatch.json /tmp/docker.json /tmp/riju.service \ + /tmp/docker.json /tmp/riju.service \ /tmp/riju.slice /tmp/riju-init-volume /tmp/riju-supervisor sudo mv /tmp/docker.json /etc/docker/daemon.json sudo mv /tmp/riju.service /tmp/riju.slice /etc/systemd/system/ -sudo mv /tmp/cloudwatch.json /opt/aws/amazon-cloudwatch-agent/bin/config.json sudo mv /tmp/riju-init-volume /tmp/riju-supervisor /usr/local/bin/ sudo sed -Ei 's|^#?PermitRootLogin .*|PermitRootLogin no|' /etc/ssh/sshd_config @@ -69,7 +65,6 @@ sudo sed -Ei "s|\\\$SUPERVISOR_ACCESS_TOKEN|${SUPERVISOR_ACCESS_TOKEN}|" /etc/sy sudo passwd -l root sudo useradd admin -g admin -G sudo -s /usr/bin/bash -p "$(echo "${ADMIN_PASSWORD}" | mkpasswd -s)" -m -sudo amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json sudo systemctl enable riju if [[ -n "${GRAFANA_API_KEY:-}" ]]; then diff --git a/packer/web.pkr.hcl b/packer/web.pkr.hcl index 9244348..a7a7ff5 100644 --- a/packer/web.pkr.hcl +++ b/packer/web.pkr.hcl @@ -87,11 +87,6 @@ source "amazon-ebs" "ubuntu" { build { sources = ["source.amazon-ebs.ubuntu"] - provisioner "file" { - destination = "/tmp/cloudwatch.json" - source = "cloudwatch.json" - } - provisioner "file" { destination = "/tmp/docker.json" source = "docker.json" diff --git a/tf/cloudwatch.tf b/tf/cloudwatch.tf deleted file mode 100644 index 130fd9b..0000000 --- a/tf/cloudwatch.tf +++ /dev/null @@ -1,174 +0,0 @@ -resource "aws_cloudwatch_metric_alarm" "server_cpu" { - alarm_name = "riju-server-cpu-high" - comparison_operator = "GreaterThanOrEqualToThreshold" - evaluation_periods = "30" - datapoints_to_alarm = "15" - metric_name = "cpu_usage_active" - namespace = "CWAgent" - period = "60" - statistic = "Average" - threshold = "70" - alarm_description = "Average CPU usage on Riju server is above 70% for 30 minutes" - ok_actions = [aws_sns_topic.riju.arn] - alarm_actions = [aws_sns_topic.riju.arn] - insufficient_data_actions = [aws_sns_topic.riju.arn] - dimensions = { - RijuInstanceGroup = "Webserver" - } - - tags = { - BillingSubcategory = "Riju:CloudWatch:Alarm" - } -} - -resource "aws_cloudwatch_metric_alarm" "server_memory" { - alarm_name = "riju-server-memory-high" - comparison_operator = "GreaterThanOrEqualToThreshold" - evaluation_periods = "30" - datapoints_to_alarm = "15" - metric_name = "mem_used_percent" - namespace = "CWAgent" - period = "60" - statistic = "Average" - threshold = "70" - alarm_description = "Average memory usage on Riju server is above 70% for 30 minutes" - ok_actions = [aws_sns_topic.riju.arn] - alarm_actions = [aws_sns_topic.riju.arn] - insufficient_data_actions = [aws_sns_topic.riju.arn] - dimensions = { - RijuInstanceGroup = "Webserver" - } - - tags = { - BillingSubcategory = "Riju:CloudWatch:Alarm" - } -} - -resource "aws_cloudwatch_metric_alarm" "server_data_volume_disk_space" { - alarm_name = "riju-server-data-volume-disk-usage-high" - comparison_operator = "GreaterThanOrEqualToThreshold" - evaluation_periods = "5" - datapoints_to_alarm = "5" - metric_name = "disk_used_percent" - namespace = "CWAgent" - period = "60" - statistic = "Average" - threshold = "70" - alarm_description = "Disk space usage for data volume on Riju server is above 70%" - ok_actions = [aws_sns_topic.riju.arn] - alarm_actions = [aws_sns_topic.riju.arn] - insufficient_data_actions = [aws_sns_topic.riju.arn] - dimensions = { - RijuInstanceGroup = "Webserver" - path = "/mnt/riju" - } - - tags = { - BillingSubcategory = "Riju:CloudWatch:Alarm" - } -} - -resource "aws_cloudwatch_metric_alarm" "server_root_volume_disk_space" { - alarm_name = "riju-server-root-volume-disk-usage-high" - comparison_operator = "GreaterThanOrEqualToThreshold" - evaluation_periods = "5" - datapoints_to_alarm = "5" - metric_name = "disk_used_percent" - namespace = "CWAgent" - period = "60" - statistic = "Average" - threshold = "70" - alarm_description = "Disk space usage for root volume on Riju server is above 70%" - ok_actions = [aws_sns_topic.riju.arn] - alarm_actions = [aws_sns_topic.riju.arn] - insufficient_data_actions = [aws_sns_topic.riju.arn] - dimensions = { - RijuInstanceGroup = "Webserver" - path = "/" - } - - tags = { - BillingSubcategory = "Riju:CloudWatch:Alarm" - } -} - -resource "aws_cloudwatch_dashboard" "riju" { - dashboard_name = "Riju" - dashboard_body = <