AWS:将Java应用程序日志记录到AWS CloudWatch

huangapple go评论80阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年4月5日 20:15:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/61042423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定