From 9c14d2e72e2c5e9ee174ff89a5b275716a36ece7 Mon Sep 17 00:00:00 2001 From: xpk Date: Fri, 3 Sep 2021 13:49:58 +0800 Subject: [PATCH] first commit --- README.md | 1 + tasks/main.yml | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 README.md create mode 100644 tasks/main.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..a373b2a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Ansible role for installing cloudwatch agent on deb-based Linux. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..8ffd3d0 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,59 @@ +- name: Install collectd + apt: + name: collectd + state: present + +- name: Install CloudWatch agent for Ubuntu + apt: + deb: https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb + state: present + +- name: Create basic CW agent config + copy: + dest: /opt/aws/amazon-cloudwatch-agent/bin/config.json + backup: yes + content: | + { + "agent": { + "metrics_collection_interval": 60, + "run_as_user": "cwagent" + }, + "metrics": { + "namespace": "CWAgent", + "append_dimensions": { + "AutoScalingGroupName": "${aws:AutoScalingGroupName}", + "ImageId": "${aws:ImageId}", + "InstanceId": "${aws:InstanceId}", + "InstanceType": "${aws:InstanceType}" + }, + "metrics_collected": { + "collectd": { + "metrics_aggregation_interval": 60 + }, + "disk": { + "measurement": [ + "used_percent" + ], + "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" + } + } + } + } + +- name: Enable and start agent + shell: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s +