-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added logic to collect logs on bottlerocket AMI #870
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
export LANG="C" | ||
export LC_ALL="C" | ||
|
||
# Global options | ||
BOTTLEROCKET_ROOTFS="/.bottlerocket/rootfs" | ||
readonly CURRENT_TIME=$(date --utc +%Y-%m-%d_%H%M-%Z) | ||
readonly PROGRAM_VERSION="0.6.2" | ||
readonly LOG_DIR="/var/log" | ||
INSTANCE_ID="" | ||
|
||
BOTTLEROCKET_UTILS=( | ||
tar | ||
) | ||
|
||
is_diskfull() { | ||
local threshold | ||
local result | ||
|
||
# 1.5GB in KB | ||
threshold=1500000 | ||
result=$(df / | grep --invert-match "Filesystem" | awk '{ print $4 }') | ||
|
||
# If "result" is less than or equal to "threshold", fail. | ||
if [[ "${result}" -le "${threshold}" ]]; then | ||
die "Free space on root volume is less than or equal to $((threshold>>10))MB, please ensure adequate disk space to collect and store the log files." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't see Try to run with
and
or
|
||
fi | ||
} | ||
|
||
collect_logs_bottlerocket() { | ||
echo "Fetching INSTANCE_ID" | ||
readonly INSTANCE_ID=$(curl --max-time 10 --retry 5 http://169.254.169.254/latest/meta-data/instance-id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if IMDSv2 enforced with SCP for Org. (or IAM policy enforced)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. related topic, |
||
if [ 0 -eq $? ]; then # Check if previous command was successful. | ||
echo "${INSTANCE_ID}" | ||
else | ||
warning "Unable to find EC2 Instance Id. Skipped Instance Id." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
fi | ||
|
||
if [ ! -d "${BOTTLEROCKET_ROOTFS}/tmp/ekslogs" ]; then | ||
echo "Creating ekslogs directory" | ||
mkdir ${BOTTLEROCKET_ROOTFS}/tmp/ekslogs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, why not execute with |
||
fi | ||
|
||
for utils in ${BOTTLEROCKET_UTILS[*]}; do | ||
# If exit code of "command -v" not equal to 0, fail | ||
if ! command -v "${utils}" >/dev/null 2>&1; then | ||
echo -e "\nApplication \"${utils}\" is missing, will install \"${utils}\"." | ||
sudo yum install -y "${utils}" | ||
fi | ||
done | ||
|
||
cp ${BOTTLEROCKET_ROOTFS}/var/log/aws-routed-eni/* ${BOTTLEROCKET_ROOTFS}/tmp/ekslogs/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it could be simplified as follow,
|
||
sudo sheltie logdog | ||
sudo sheltie cp /var/log/support/bottlerocket-logs.tar.gz /tmp/ekslogs | ||
tar -cvzf "${LOG_DIR}"/eks_"${INSTANCE_ID}"_"${CURRENT_TIME}"_"${PROGRAM_VERSION}".tar.gz "${BOTTLEROCKET_ROOTFS}"/tmp/ekslogs > /dev/null 2>&1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, it should be an optional action as we already have |
||
} | ||
|
||
finished() { | ||
cleanup | ||
echo -e "\n\tDone... your bundled logs are located in ${LOG_DIR}/eks_${INSTANCE_ID}_${CURRENT_TIME}_${PROGRAM_VERSION}.tar.gz\n" | ||
} | ||
|
||
cleanup() { | ||
# bottlerocket AMI | ||
if [ -d "/.bottlerocket/" ]; then | ||
rm --recursive --force {BOTTLEROCKET_ROOTFS}/tmp/ekslogs > /dev/null 2>&1 | ||
else | ||
echo "Unable to Cleanup as {COLLECT_DIR} variable is modified. Please cleanup manually!" | ||
fi | ||
} | ||
Comment on lines
+62
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about...
Why we need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think PR was work in progress, we are anyway not merging in this repo. |
||
|
||
echo "Detected Bottlerocket AMI" | ||
is_diskfull | ||
collect_logs_bottlerocket | ||
finished |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing shebang?
#!/bin/sh
,!/bin/bash
or!/usr/bin/env bash
. and Copyrights?https://github.com/awslabs/amazon-eks-ami/blob/master/log-collector-script/linux/eks-log-collector.sh#L1-L18