Last active
February 26, 2020 19:32
-
-
Save Techbrunch/8bc8a2888defd7fecb24 to your computer and use it in GitHub Desktop.
Monitoring CakePHP logs with CloudWatch & Elastic Beanstalk
This file contains 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
Mappings: | |
CWLogs: | |
CakeErrorLogGroup: | |
LogFile: "/var/www/html/project/tmp/logs/error.log" | |
TimestampFormat: "%m-%d-%Y %H:%M:%S" | |
FilterPatterns: | |
AllCakeErrorsFilter: "[timestamp, type = *Error*, ...]" | |
Outputs: | |
CakeErrorCWLogGroup: | |
Description: "Cake error log - CakeErrorCWLogGroup" | |
Value: { "Ref" : "AWSEBCloudWatchLogsCakeErrorLogGroup"} | |
Resources : | |
AWSEBCloudWatchLogsCakeErrorLogGroup: | |
Type: "AWS::Logs::LogGroup" | |
DependsOn: AWSEBBeanstalkMetadata | |
DeletionPolicy: Retain ## this is required | |
Properties: | |
LogGroupName: | |
"Fn::GetOptionSetting": | |
Namespace: "aws:elasticbeanstalk:application:environment" | |
OptionName: CakeErrorCWLogGroup | |
DefaultValue: {"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "cakeerrors"]]} | |
RetentionInDays: 14 | |
AWSEBAutoScalingGroup: | |
Metadata: | |
"AWS::CloudFormation::Init": | |
CWLogsAgentConfigSetup: | |
files: | |
"/tmp/cwlogs/conf.d/cake-error.conf": | |
content : | | |
[cake-error_log] | |
file = `{"Fn::FindInMap":["CWLogs", "CakeErrorLogGroup", "LogFile"]}` | |
log_group_name = `{ "Ref" : "AWSEBCloudWatchLogsCakeErrorLogGroup" }` | |
log_stream_name = {instance_id} | |
datetime_format = `{"Fn::FindInMap":["CWLogs", "CakeErrorLogGroup", "TimestampFormat"]}` | |
mode : "000400" | |
owner : root | |
group : root | |
AWSEBCWLAllCakeErrorsFilter : | |
Type : "AWS::Logs::MetricFilter" | |
Properties : | |
LogGroupName: { "Ref" : "AWSEBCloudWatchLogsCakeErrorLogGroup" } | |
FilterPattern : {"Fn::FindInMap":["CWLogs", "FilterPatterns", "AllCakeErrorsFilter"]} | |
MetricTransformations : | |
- MetricValue : 1 | |
MetricNamespace: {"Fn::Join":["/", ["ElasticBeanstalk", {"Ref":"AWSEBEnvironmentName"}]]} | |
MetricName : CWLAllErrorRecords | |
AWSEBCWLAllCakeErrorsCountAlarm : | |
Type : "AWS::CloudWatch::Alarm" | |
DependsOn : AWSEBCWLAllCakeErrorsFilter | |
Properties : | |
AlarmDescription: "Cake generated an error in /var/www/html/project/logs/errors.log" | |
MetricName: CWLAllErrorRecords | |
Name: {"Fn::Join":["-", ["ElasticBeanstalk-AWSEBCWLAllCakeErrorsCountAlarm", {"Ref":"AWSEBEnvironmentName"}]]} | |
Namespace: {"Fn::Join":["/", ["ElasticBeanstalk", {"Ref":"AWSEBEnvironmentName"}]]} | |
Statistic: Sum | |
Period: 60 | |
EvaluationPeriods: 1 | |
Threshold: 0 | |
ComparisonOperator: GreaterThanThreshold | |
AlarmActions: | |
- "Fn::If": | |
- SNSTopicExists | |
- "Fn::FindInMap": | |
- AWSEBOptions | |
- options | |
- EBSNSTopicArn | |
- { "Ref" : "AWS::NoValue" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I was using this config in my EB and found that the creation of the environment failed because of line 64 with the error:
"Creating CloudWatch alarm failed Reason: Encountered unsupported property Name"
It looks like the property "Name" should be "AlarmName" for it to work.