Skip to content

Commit 5756f14

Browse files
committed
Add opt-in default metrics to CloudWatch agent
Report on memory and disk usage
1 parent 509802d commit 5756f14

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC2094
3+
set -euo pipefail
4+
5+
if [[ "${CLOUDWATCH_ENABLE_METRICS:-false}" == "true" ]]; then
6+
cw_config="/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json"
7+
cat <<<"$(jq \
8+
--arg queue "$BUILDKITE_QUEUE" \
9+
'. + {
10+
metrics: {
11+
metrics_collected: {
12+
mem: {measurement: ["mem_used_percent"], append_dimensions: {BuildkiteQueue: $queue}},
13+
disk: {measurement: ["used_percent"], resources: ["*"], append_dimensions: {BuildkiteQueue: $queue}}
14+
},
15+
append_dimensions: {
16+
AutoScalingGroupName: "${aws:AutoScalingGroupName}"
17+
}
18+
}
19+
}' $cw_config)" >$cw_config
20+
fi
21+
22+
# Enable and start amazon-cloudwatch-agent
23+
systemctl enable amazon-cloudwatch-agent
24+
systemctl start amazon-cloudwatch-agent

packer/linux/scripts/install-cloudwatch-agent.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
set -eu -o pipefail
44

5-
65
echo "Installing cloudwatch agent..."
76
sudo yum install -y amazon-cloudwatch-agent
87

98
echo "Adding amazon-cloudwatch-agent config..."
109
sudo cp /tmp/conf/cloudwatch-agent/config.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
1110

12-
echo "Configuring amazon-cloudwatch-agent to start at boot"
13-
sudo systemctl enable amazon-cloudwatch-agent
14-
1511
# These will send some systemctl service logs (like the buildkite agent and docker) to logfiles
1612
echo "Adding rsyslogd configs..."
1713
sudo cp /tmp/conf/cloudwatch-agent/rsyslog.d/* /etc/rsyslog.d/

templates/aws-stack.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Metadata:
7575
- ManagedPolicyARN
7676
- InstanceRoleName
7777
- IMDSv2Tokens
78+
- EnableCloudWatchMetrics
7879

7980
- Label:
8081
default: Auto-scaling Configuration
@@ -417,6 +418,14 @@ Parameters:
417418
- "false"
418419
Default: "false"
419420

421+
EnableCloudWatchMetrics:
422+
Type: String
423+
Description: Enable CloudWatch agent metrics
424+
AllowedValues:
425+
- "true"
426+
- "false"
427+
Default: "false"
428+
420429
EnableCostAllocationTags:
421430
Type: String
422431
Description: Enables AWS Cost Allocation tags for all resources in the stack. See https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html
@@ -1016,6 +1025,11 @@ Resources:
10161025
BUILDKITE_ENABLE_INSTANCE_STORAGE="${EnableInstanceStorage}" \
10171026
/usr/local/bin/bk-configure-docker.sh
10181027
--==BOUNDARY==
1028+
Content-Type: text/cloud-boothook; charset="us-ascii"
1029+
CLOUDWATCH_ENABLE_METRICS="${EnableCloudWatchMetrics}" \
1030+
BUILDKITE_QUEUE="${BuildkiteQueue}" \
1031+
/usr/local/bin/bk-configure-cloudwatch-agent.sh
1032+
--==BOUNDARY==
10191033
Content-Type: text/x-shellscript; charset="us-ascii"
10201034
#!/bin/bash -v
10211035
BUILDKITE_STACK_NAME="${AWS::StackName}" \

0 commit comments

Comments
 (0)