2 Answers
- Newest
- Most votes
- Most comments
1
Hello.
Can you confirm that the CloudWatch Agent is running on your EC2 instance?
Also, check the CloudWatch Agent logs to see if any errors are output.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html#CloudWatch-Agent-files-and-locations
/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log or /var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log
0
files:
# ####################################################################################################################
# First we create a custom config file that lists additional files that should be included when we request
# "Last 100 lines" of the logs (not just when we select "Full").
# Note: Several other files are included by default.
# This ".conf" file is picked up automatically since it is added to the taillogs.d folder.
# See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.logging.html
# ####################################################################################################################
"/opt/elasticbeanstalk/tasks/taillogs.d/my-company-tail-log.conf" :
mode: "000755"
owner: root
group: root
content: |
/var/log/cfn-init-cmd.log
# ####################################################################################################################
# We also create a custom config file to specify that the application.log file should be streamed to Cloudwatch,
# (in addition to other files that are streamed to Cloudwatch by default, like eb-engine.log, eb-hooks.log etc)
# This ".json" file is not picked up automatically, but we point to it in the container_commands below.
# ####################################################################################################################
"/opt/aws/amazon-cloudwatch-agent/etc/my-company-amazon-cloudwatch-agent.json":
mode: "000600"
owner: root
group: root
content: |
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/tomcat9/application.log",
"log_group_name": "`{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat9/application.log"]]}`",
"log_stream_name": "{instance_id}",
"timestamp_format": "%Y-%m-%d %H:%M:%S.%f"
}
]
}
}
}
}
# ####################################################################################################################
# Note: The execution of the commands below is logged in file cfn-init-cmd.log
# ####################################################################################################################
container_commands:
"01":
command: |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/my-company-amazon-cloudwatch-agent.json
This is what my coworker ended up using which worked for populating the cloudwatch logs. There are some comments that explain what's going on in this config file, but I don't understand it enough to explain it, so I will leave this question unanswered. If anyone can explain why this is working in a comment I will accept this answer.
answered a month ago
Relevant content
- asked 2 years ago
- Accepted Answerasked 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 months ago
I appreciate the quick response. From
messages
log:I'm not sure where to locate the cloudwatch agent logs, but if I'm understanding correctly from the logs above, the cloudwatch agent is running on the EC2 instance.
CloudWatch Agent logs should be output to one of the following locations. Can you check the logs below to see if there are any errors?