Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 26d63b2

Browse files
author
Irving Popovetsky
authored
Merge pull request #29 from chef-customers/cloudwatch_logs
Logs-o-rama!
2 parents 56713f4 + b826d5c commit 26d63b2

File tree

2 files changed

+321
-4
lines changed

2 files changed

+321
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ MYBUCKET=aws-native-chef-server
4848
aws s3 cp backendless_chef.yaml s3://$MYBUCKET/
4949
aws cloudformation validate-template --template-url https://s3.amazonaws.com/$MYBUCKET/backendless_chef.yaml
5050
aws cloudformation update-stack \
51-
--stack-name irving-backendless-chef2 \
51+
--stack-name irving-backendless-chef \
5252
--template-url https://s3.amazonaws.com/$MYBUCKET/backendless_chef.yaml \
5353
--capabilities CAPABILITY_IAM \
5454
--parameters file://stack_parameters.json

backendless_chef.yaml

Lines changed: 320 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Description: AWS Native Chef Server v3.1.3
2+
Description: AWS Native Chef Server v3.2.0
33

44
Parameters:
55
# Required Parameters
@@ -179,6 +179,11 @@ Parameters:
179179
Type: String
180180
Default: 'chef'
181181
Description: Supply a DNS record name that will be prepended to the Route 53 Hosted Zone
182+
LogsRetentionInDays:
183+
Description: Specifies the number of days you want to retain cloudwatch log events.
184+
Type: Number
185+
Default: 90
186+
AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
182187

183188
Metadata:
184189
AWS::CloudFormation::Interface:
@@ -412,9 +417,10 @@ Resources:
412417
- Action: cloudwatch:ListMetrics
413418
Effect: Allow
414419
Resource: "*"
415-
- Action: logs:*
420+
# Allow instances to write to cloudwatch logs
421+
- Action: ["logs:PutLogEvents", "logs:CreateLogStream", "logs:CreateLogGroup"]
416422
Effect: Allow
417-
Resource: arn:aws:logs:*.*.*
423+
Resource: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${AWS::StackName}*
418424
Roles:
419425
- !Ref ChefRole
420426

@@ -621,6 +627,8 @@ Resources:
621627
/opt/aws/bin/cfn-signal -e 0 -r "Server setup complete" '${WaitHandle}'
622628
Metadata:
623629
AWS::CloudFormation::Init:
630+
configSets:
631+
default: [awslogs, config, filebeat]
624632
config:
625633
packages:
626634
rpm:
@@ -743,6 +751,161 @@ Resources:
743751
unzip CloudWatchMonitoringScripts-1.2.1.zip
744752
rm CloudWatchMonitoringScripts-1.2.1.zip
745753
crontab -l | { cat; echo "*/5 * * * * /opt/cloudwatch_monitoring/aws-scripts-mon/mon-put-instance-data.pl --auto-scaling --mem-util --disk-space-util --disk-path=/ --from-cron"; } | crontab -
754+
awslogs:
755+
packages:
756+
yum:
757+
awslogs: []
758+
files:
759+
/etc/awslogs/awscli.conf:
760+
content: !Sub |
761+
[default]
762+
region = ${AWS::Region}
763+
[plugins]
764+
cwlogs = cwlogs
765+
mode: '000644'
766+
owner: root
767+
group: root
768+
/etc/awslogs/awslogs.conf:
769+
content: !Sub |
770+
[general]
771+
state_file = /var/lib/awslogs/agent-state
772+
[/var/log/messages]
773+
datetime_format = %b %d %H:%M:%S
774+
file = /var/log/messages
775+
log_stream_name = {instance_id}
776+
log_group_name = ${VarLogMessages}
777+
[/var/log/secure]
778+
datetime_format = %b %d %H:%M:%S
779+
file = /var/log/secure
780+
log_stream_name = {instance_id}
781+
log_group_name = ${VarLogSecure}
782+
[/var/log/cron]
783+
datetime_format = %b %d %H:%M:%S
784+
file = /var/log/cron
785+
log_stream_name = {instance_id}
786+
log_group_name = ${VarLogCron}
787+
[/var/log/cloud-init.log]
788+
datetime_format = %b %d %H:%M:%S
789+
file = /var/log/cloud-init.log
790+
log_stream_name = {instance_id}
791+
log_group_name = ${VarLogCloudInitLog}
792+
[/var/log/cfn-init.log]
793+
datetime_format = %Y-%m-%d %H:%M:%S
794+
file = /var/log/cfn-init.log
795+
log_stream_name = {instance_id}
796+
log_group_name = ${VarLogCfnInitLog}
797+
[/var/log/cfn-init-cmd.log]
798+
datetime_format = %Y-%m-%d %H:%M:%S
799+
file = /var/log/cfn-init-cmd.log
800+
log_stream_name = {instance_id}
801+
log_group_name = ${VarLogCfnInitCmdLog}
802+
[/var/log/cloud-init-output.log]
803+
file = /var/log/cloud-init-output.log
804+
log_stream_name = {instance_id}
805+
log_group_name = ${VarLogCloudInitOutputLog}
806+
[/var/log/dmesg]
807+
file = /var/log/dmesg
808+
log_stream_name = {instance_id}
809+
log_group_name = ${VarLogDmesg}
810+
[/var/log/aws-signing-proxy/proxy.log]
811+
log_group_name = ${VarLogAwsSigningProxyLog}
812+
file = /var/log/aws-signing-proxy/proxy.log
813+
log_stream_name = {instance_id}
814+
[/var/log/opscode/bookshelf/current]
815+
log_group_name = ${VarLogOpscodeBookshelfCurrent}
816+
file = /var/log/opscode/bookshelf/current
817+
log_stream_name = {instance_id}
818+
[/var/log/opscode/oc_bifrost/current]
819+
log_group_name = ${VarLogOpscodeOcBifrostCurrent}
820+
file = /var/log/opscode/oc_bifrost/current
821+
log_stream_name = {instance_id}
822+
[/var/log/opscode/opscode-erchef/current]
823+
log_group_name = ${VarLogOpscodeOpscodeErchefCurrent}
824+
file = /var/log/opscode/opscode-erchef/current
825+
log_stream_name = {instance_id}
826+
[/var/log/opscode/opscode-erchef/requests.log]
827+
log_group_name = ${VarLogOpscodeOpscodeErchefRequestsLog}
828+
file = /var/log/opscode/opscode-erchef/requests.log.*
829+
log_stream_name = {instance_id}
830+
[/var/log/opscode/opscode-pushy-server/current]
831+
log_group_name = ${VarLogOpscodeOpscodePushyServerCurrent}
832+
file = /var/log/opscode/opscode-pushy-server/current
833+
log_stream_name = {instance_id}
834+
[/var/log/opscode/redis_lb/current]
835+
log_group_name = ${VarLogOpscodeRedisLbCurrent}
836+
file = /var/log/opscode/redis_lb/current
837+
log_stream_name = {instance_id}
838+
[/var/log/opscode/oc_id/current]
839+
log_group_name = ${VarLogOpscodeOcIdCurrent}
840+
file = /var/log/opscode/oc_id/current
841+
log_stream_name = {instance_id}
842+
[/var/log/opscode/nginx/access.log]
843+
log_group_name = ${VarLogOpscodeNginxAccessLog}
844+
file = /var/log/opscode/nginx/access.log
845+
log_stream_name = {instance_id}
846+
[/var/log/opscode/nginx/error.log]
847+
log_group_name = ${VarLogOpscodeNginxErrorLog}
848+
file = /var/log/opscode/nginx/error.log
849+
log_stream_name = {instance_id}
850+
[/var/log/chef-manage/redis/current]
851+
log_group_name = ${VarLogChefManageRedisCurrent}
852+
file = /var/log/chef-manage/redis/current
853+
log_stream_name = {instance_id}
854+
[/var/log/chef-manage/web/current]
855+
log_group_name = ${VarLogChefManageWebCurrent}
856+
file = /var/log/chef-manage/web/current
857+
log_stream_name = {instance_id}
858+
[/var/log/chef-manage/worker/current]
859+
log_group_name = ${VarLogChefManageWorkerCurrent}
860+
file = /var/log/chef-manage/worker/current
861+
log_stream_name = {instance_id}
862+
mode: '000644'
863+
owner: root
864+
group: root
865+
services:
866+
sysvinit:
867+
awslogs:
868+
enabled: true
869+
ensureRunning: true
870+
packages:
871+
yum:
872+
- awslogs
873+
files:
874+
- /etc/awslogs/awslogs.conf
875+
- /etc/awslogs/awscli.conf
876+
filebeat:
877+
packages:
878+
rpm:
879+
filebeat: https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.6.6-x86_64.rpm
880+
files:
881+
/etc/filebeat/filebeat.yml:
882+
content: !Sub |
883+
filebeat.prospectors:
884+
- input_type: log
885+
paths:
886+
- /var/log/*
887+
- /var/log/opscode/*/current
888+
- /var/log/opscode/nginx/*.log
889+
- /var/log/opscode/opscode-erchef/requests.log.*
890+
- /var/log/chef-manage/*/current
891+
output.elasticsearch:
892+
hosts: ["localhost:9200"]
893+
setup.kibana:
894+
host: "http://localhost:9200/_plugin/kibana/"
895+
dashboards.enabled: true
896+
mode: '000644'
897+
owner: root
898+
group: root
899+
services:
900+
sysvinit:
901+
filebeat:
902+
enabled: true
903+
ensureRunning: true
904+
packages:
905+
rpm:
906+
- filebeat
907+
files:
908+
- /etc/filebeat/filebeat.yml
746909

747910
WaitCondition:
748911
Type: AWS::CloudFormation::WaitCondition
@@ -862,6 +1025,113 @@ Resources:
8621025
ResourceRecords:
8631026
- !GetAtt ChefALB.DNSName
8641027

1028+
# Logging Groups (Cloudwatch Logs)
1029+
#########################################################################################
1030+
VarLogMessages:
1031+
Type: AWS::Logs::LogGroup
1032+
Properties:
1033+
RetentionInDays: !Ref LogsRetentionInDays
1034+
1035+
VarLogSecure:
1036+
Type: AWS::Logs::LogGroup
1037+
Properties:
1038+
RetentionInDays: !Ref LogsRetentionInDays
1039+
1040+
VarLogCron:
1041+
Type: AWS::Logs::LogGroup
1042+
Properties:
1043+
RetentionInDays: !Ref LogsRetentionInDays
1044+
1045+
VarLogCloudInitLog:
1046+
Type: AWS::Logs::LogGroup
1047+
Properties:
1048+
RetentionInDays: !Ref LogsRetentionInDays
1049+
1050+
VarLogCloudInitOutputLog:
1051+
Type: AWS::Logs::LogGroup
1052+
Properties:
1053+
RetentionInDays: !Ref LogsRetentionInDays
1054+
1055+
VarLogCfnInitLog:
1056+
Type: AWS::Logs::LogGroup
1057+
Properties:
1058+
RetentionInDays: !Ref LogsRetentionInDays
1059+
1060+
VarLogCfnInitCmdLog:
1061+
Type: AWS::Logs::LogGroup
1062+
Properties:
1063+
RetentionInDays: !Ref LogsRetentionInDays
1064+
1065+
VarLogDmesg:
1066+
Type: AWS::Logs::LogGroup
1067+
Properties:
1068+
RetentionInDays: !Ref LogsRetentionInDays
1069+
1070+
VarLogAwsSigningProxyLog:
1071+
Type: AWS::Logs::LogGroup
1072+
Properties:
1073+
RetentionInDays: !Ref LogsRetentionInDays
1074+
1075+
VarLogOpscodeBookshelfCurrent:
1076+
Type: AWS::Logs::LogGroup
1077+
Properties:
1078+
RetentionInDays: !Ref LogsRetentionInDays
1079+
1080+
VarLogOpscodeOcBifrostCurrent:
1081+
Type: AWS::Logs::LogGroup
1082+
Properties:
1083+
RetentionInDays: !Ref LogsRetentionInDays
1084+
1085+
VarLogOpscodeOpscodeErchefCurrent:
1086+
Type: AWS::Logs::LogGroup
1087+
Properties:
1088+
RetentionInDays: !Ref LogsRetentionInDays
1089+
1090+
VarLogOpscodeOpscodeErchefRequestsLog:
1091+
Type: AWS::Logs::LogGroup
1092+
Properties:
1093+
RetentionInDays: !Ref LogsRetentionInDays
1094+
1095+
VarLogOpscodeOpscodePushyServerCurrent:
1096+
Type: AWS::Logs::LogGroup
1097+
Properties:
1098+
RetentionInDays: !Ref LogsRetentionInDays
1099+
1100+
VarLogOpscodeRedisLbCurrent:
1101+
Type: AWS::Logs::LogGroup
1102+
Properties:
1103+
RetentionInDays: !Ref LogsRetentionInDays
1104+
1105+
VarLogOpscodeOcIdCurrent:
1106+
Type: AWS::Logs::LogGroup
1107+
Properties:
1108+
RetentionInDays: !Ref LogsRetentionInDays
1109+
1110+
VarLogOpscodeNginxAccessLog:
1111+
Type: AWS::Logs::LogGroup
1112+
Properties:
1113+
RetentionInDays: !Ref LogsRetentionInDays
1114+
1115+
VarLogOpscodeNginxErrorLog:
1116+
Type: AWS::Logs::LogGroup
1117+
Properties:
1118+
RetentionInDays: !Ref LogsRetentionInDays
1119+
1120+
VarLogChefManageRedisCurrent:
1121+
Type: AWS::Logs::LogGroup
1122+
Properties:
1123+
RetentionInDays: !Ref LogsRetentionInDays
1124+
1125+
VarLogChefManageWebCurrent:
1126+
Type: AWS::Logs::LogGroup
1127+
Properties:
1128+
RetentionInDays: !Ref LogsRetentionInDays
1129+
1130+
VarLogChefManageWorkerCurrent:
1131+
Type: AWS::Logs::LogGroup
1132+
Properties:
1133+
RetentionInDays: !Ref LogsRetentionInDays
1134+
8651135
# Monitoring
8661136
#########################################################################################
8671137
AlertNotificationTopic:
@@ -916,6 +1186,51 @@ Resources:
9161186
- Name: Filesystem
9171187
Value: /dev/xvda1
9181188

1189+
DiskSpaceUtilizationNvme:
1190+
Type: AWS::CloudWatch::Alarm
1191+
Properties:
1192+
AlarmName: !Sub DiskSpaceUtilizationNvme-${AWS::StackName}
1193+
AlarmDescription: Alarms when an disk utilization reaches a specified threshold.
1194+
AlarmActions: [!Ref AlertNotificationTopic]
1195+
MetricName: DiskSpaceUtilization
1196+
Namespace: System/Linux
1197+
ComparisonOperator: GreaterThanOrEqualToThreshold
1198+
EvaluationPeriods: 2
1199+
Period: 300
1200+
Statistic: Average
1201+
Threshold: 80
1202+
Unit: Percent
1203+
Dimensions:
1204+
- Name: AutoScalingGroupName
1205+
Value: !Ref FrontendAutoScaleGroup
1206+
- Name: MountPath
1207+
Value: '/'
1208+
- Name: Filesystem
1209+
Value: /dev/nvme0n1p1
1210+
1211+
BootstrapDiskSpaceUtilizationNvme:
1212+
Type: AWS::CloudWatch::Alarm
1213+
Properties:
1214+
AlarmName: !Sub DiskSpaceUtilizationNvme-bootstrap-${AWS::StackName}
1215+
AlarmDescription: Alarms when an disk utilization reaches a specified threshold.
1216+
AlarmActions: [!Ref AlertNotificationTopic]
1217+
MetricName: DiskSpaceUtilization
1218+
Namespace: System/Linux
1219+
ComparisonOperator: GreaterThanOrEqualToThreshold
1220+
EvaluationPeriods: 2
1221+
Period: 300
1222+
Statistic: Average
1223+
Threshold: 80
1224+
Unit: Percent
1225+
Dimensions:
1226+
- Name: AutoScalingGroupName
1227+
Value: !Ref BootstrapAutoScaleGroup
1228+
- Name: MountPath
1229+
Value: '/'
1230+
- Name: Filesystem
1231+
Value: /dev/nvme0n1p1
1232+
1233+
9191234
MemoryUtilization:
9201235
Type: AWS::CloudWatch::Alarm
9211236
Properties:
@@ -1136,6 +1451,8 @@ Resources:
11361451
"stacked": false,
11371452
"metrics": [
11381453
[ "System/Linux", "DiskSpaceUtilization", "MountPath", "/", "AutoScalingGroupName", "${BootstrapAutoScaleGroup}", "Filesystem", "/dev/xvda1", { "period": 60 } ],
1454+
[ "...", "${FrontendAutoScaleGroup}", ".", ".", { "period": 60 } ],
1455+
[ "System/Linux", "DiskSpaceUtilization", "MountPath", "/", "AutoScalingGroupName", "${BootstrapAutoScaleGroup}", "Filesystem", "/dev/nvme0n1p1", { "period": 60 } ],
11391456
[ "...", "${FrontendAutoScaleGroup}", ".", ".", { "period": 60 } ]
11401457
],
11411458
"region": "${AWS::Region}",

0 commit comments

Comments
 (0)