Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS logs agent setup

We have recently setup AWS logs agent on one of our test servers. Our log files usually contain multi-line events. e.g one of our log event is:

[10-Jun-2016 07:30:16 UTC] SQS Post Response: Array
(
    [Status] => 200
    [ResponseBody] => <?xml version="1.0"?><SendMessageResponse xmlns="http://queue.amazonaws.com/doc/2009-02-01/"><SendMessageResult><MessageId>053c7sdf5-1e23-wa9d-99d8-2a0cf9eewe7a</MessageId><MD5OfMessageBody>8e542d2c2a1325a85eeb9sdfwersd58f</MD5OfMessageBody></SendMessageResult><ResponseMetadata><RequestId>4esdfr30-c39b-526b-bds2-14e4gju18af</RequestId></ResponseMetadata></SendMessageResponse>
)

The log agent reference documentation says to use 'multi_line_start_pattern' option for such logs. Our AWS Log agent config is as follows:

[httpd_info.log]
file = /var/log/httpd/info.log*
log_stream_name = info.log
initial_position = start_of_file
log_group_name = test.server.name
multi_line_start_pattern = '(\[)+\d{2}-[a-zA-Z]{3}+-\d{4}'

However, the logs agent reporting breaks on aforementioned and similar events. The way it is being reported to CloudWatch Logs is as follows:

Event 1:

[10-Jun-2016 11:21:26 UTC] SQS Post Response: Array

Event 2:

( [Status] => 200 [ResponseBody] => <?xml version="1.0"?><SendMessageResponse xmlns="http://queue.amazonaws.com/doc/2009-02-01/"><SendMessageResult><MessageId>053c7sdf5-1e23-wa9d-99d8-2a0cf9eewe7a</MessageId><MD5OfMessageBody>8e542d2c2a1325a85eeb9sdfwersd58f</MD5OfMessageBody></SendMessageResult><ResponseMetadata><RequestId>4esdfr30-c39b-526b-bds2-14e4gju18af</RequestId></ResponseMetadata></SendMessageResponse>

Event 3:

)

Despite of the fact that its only a single event. Any clue whats going on here?

like image 1000
Furhan S. Avatar asked Jun 10 '16 11:06

Furhan S.


People also ask

What is Amazon CloudWatch logs agent?

The CloudWatch Logs agent provides an automated way to send log data to CloudWatch Logs from Amazon EC2 instances. The agent includes the following components: A plug-in to the AWS CLI that pushes log data to CloudWatch Logs. A script (daemon) that initiates the process to push data to CloudWatch Logs.

How do I enable AWS CloudWatch logs?

On the Stage Editor pane, choose the Logs/Tracing tab. 3. On the Logs/Tracing tab, under CloudWatch Settings, do the following to turn on execution logging: Choose the Enable CloudWatch Logs check box.


1 Answers

I think all you need to add is the following to your awslogs.conf

datetime_format = %d-%b-%Y %H:%M:%S UTC
time_zone = UTC
multi_line_start_pattern = {datetime_format}

http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html

multi_line_start_pattern

Specifies the pattern for identifying the start of a log message. A log message is made of a line that matches the pattern and any following lines that don't match the pattern. The valid values are regular expression or {datetime_format}. When using {datetime_format}, the datetime_format option should be specified. The default value is ‘^[^\s]' so any line that begins with non-whitespace character closes the previous log message and starts a new log message.

If that datetime format didn't work, you would need to update your regex to actually match your specific datetime. I don't think the one you have listed above actually works for your given format.

You could try this for instance:

[\d{2}-[\w]{3}-\d{4}\s{1}\d{2}:\d{2}:\d{2}\s{1}\w+]

does match

[10-Jun-2016 11:21:26 UTC]

See here: http://www.regexpal.com/?fam=96811

Once completed, issue a restart of the service and check to see if its parsing correctly.

$ sudo service awslogs restart

like image 136
tragicrock Avatar answered Oct 23 '22 13:10

tragicrock