英文:
AWS: Java application logs to AWS Cloudwatch
问题
我有一组使用Java、Jersey2和AWS实现的RESTful API。目前我已经使用SL4J配置了日志,将其记录在本地文件中。是否有办法将这些日志发送到CloudWatch,以便我可以更好地监控日志,并在将来需要时实施告警?
英文:
I have a collection of RESTful APIs implemented using Java, Jersey2 and AWS. Currently I have configured my logs using SL4J which logs into a local file. Is there a way to send these logs to cloudwatch so that I can monitor the logs better and implement alarms in future when needed?
答案1
得分: 1
你需要在实例上安装 CloudWatch 日志代理,并通过在 /etc/awslogs/config/
中创建类似此示例的配置文件来配置它以监控日志文件:
[mylogfile.log]
datetime_format = %m/%d/%y-%H:%M:%L
file = /folder/mylogfile.log
buffer_duration = 5000
log_stream_name = {instance_id}-{hostname}-{ip_address}-mylogfile.log
initial_position = start_of_file
log_group_name = MyApplicationLogGroup
以下是带有日志记录和监控的完整示例:https://github.com/antonum/CloudWatch-IRIS
英文:
You need to install CloudWatch Log Agent on the instance and configure it to monitor your log file, by creating config file like this one in /etc/awslogs/config/
:
[mylogfile.log]
datetime_format = %m/%d/%y-%H:%M:%L
file = /folder/mylogfile.log
buffer_duration = 5000
log_stream_name = {instance_id}-{hostname}-{ip_address}-mylogfile.log
initial_position = start_of_file
log_group_name = MyApplicationLogGroup
Here is the complete example with logging and monitoring: https://github.com/antonum/CloudWatch-IRIS
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论