Last active
December 17, 2018 13:17
-
-
Save CasperCL/a1e2f0663609657269bf4a6b26b89e3a to your computer and use it in GitHub Desktop.
Cloudwatch Load Apache2 logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /bin/bash | |
# Setup Cloudwatch config for Apache2 logs | |
ERROR_LOGS=( $( ls /var/log/apache2/*error.log ) ) | |
ACCESS_LOGS=( $( ls /var/log/apache2/*access.log ) ) | |
CONFIG_PATH="/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json" | |
CONFIG="{\"logs\":{ \"logs_collected\": { \"files\": { \"collect_list\": [" | |
LOGS=(${ERROR_LOGS[@]} ${ACCESS_LOGS[@]}) | |
for file_path in ${LOGS[@]} ; do | |
GROUP=$(basename $file_path) | |
if [ "$GROUP" == "error.log" ] || [ "$GROUP" == "other_vhosts_access.log" ]; then | |
echo "Skipping $file_path; Groupname is too generic: '$GROUP'" | |
continue | |
fi | |
CONFIG+="{\"file_path\":\"$file_path\", \"log_group_name\": \"$GROUP\" }" | |
if [ "$file_path" != "${LOGS[-1]}" ]; then | |
CONFIG+="," | |
fi | |
done | |
CONFIG+="]}}}}" | |
echo $CONFIG | python -m json.tool > $CONFIG_PATH | |
echo "Written to file: $CONFIG_PATH" | |
cat $CONFIG_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment