forked from aws/opsworks-cookbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CloudWatch Logs integration cookbook
- Loading branch information
Daniel Geng
committed
Aug 18, 2015
1 parent
dd4e422
commit 5437013
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if node["platform"] == "amazon" | ||
default["cloudwatchlogs"]["config_file"] = "/etc/awslogs/awslogs.conf" # Configures the logs for the agent to ship | ||
default["cloudwatchlogs"]["home_dir"] = "/etc/awslogs" # Contains configuration files | ||
default["cloudwatchlogs"]["state_file"] = "/var/lib/awslogs/agent-state" # See http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/QuickStartChef.html | ||
else | ||
default["cloudwatchlogs"]["config_file"] = "/opt/aws/cloudwatch/cwlogs.cfg" # Configures the logs to ship, used by installation script | ||
default["cloudwatchlogs"]["home_dir"] = "/var/awslogs" # Contains the awslogs package | ||
default["cloudwatchlogs"]["state_file"] = "/var/awslogs/state/agent-state" # See http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/QuickStartChef.html | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name "opsworks_cloudwatchlogs" | ||
description "CloudWatch Logs Integration" | ||
maintainer "AWS OpsWorks" | ||
license "Apache 2.0" | ||
version "1.0.0" | ||
|
||
recipe "opsworks_cloudwatchlogs::default", "Uses install or uninstall recipe" | ||
recipe "opsworks_cloudwatchlogs::install", "Install CloudWatch Logs agent." | ||
recipe "opsworks_cloudwatchlogs::uninstall", "Remove CloudWatch Logs agent and config files." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if node["opsworks"]["cloud_watch_logs_configurations"].any? | ||
include_recipe "opsworks_cloudwatchlogs::install" | ||
else | ||
include_recipe "opsworks_cloudwatchlogs::uninstall" | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
directory node["cloudwatchlogs"]["home_dir"] do | ||
recursive true | ||
end | ||
|
||
template node["cloudwatchlogs"]["config_file"] do | ||
source "awslogs.conf.erb" | ||
variables({ | ||
:state_file => node["cloudwatchlogs"]["state_file"], | ||
:cloudwatchlogs => node["opsworks"]["cloud_watch_logs_configurations"], | ||
:hostname => node["opsworks"]["instance"]["hostname"] | ||
}) | ||
owner "root" | ||
group "root" | ||
mode 0644 | ||
end | ||
|
||
if platform?("amazon") | ||
package "awslogs" | ||
|
||
template "#{node['cloudwatchlogs']['home_dir']}/awscli.conf" do | ||
source "awscli.conf.erb" | ||
variables :region => node["opsworks"]["instance"]["region"] | ||
end | ||
else | ||
directory "/opt/aws/cloudwatch" do | ||
recursive true | ||
end | ||
|
||
remote_file "/opt/aws/cloudwatch/awslogs-agent-setup.py" do | ||
source "https://aws-cloudwatch.s3.amazonaws.com/downloads/latest/awslogs-agent-setup.py" | ||
mode 0700 | ||
retries 3 | ||
end | ||
|
||
package "python" | ||
|
||
execute "Install CloudWatch Logs agent" do | ||
command "/opt/aws/cloudwatch/awslogs-agent-setup.py -n -r '#{node['opsworks']['instance']['region']}' -c '#{node['cloudwatchlogs']['config_file']}'" | ||
not_if { File.exists?(node["cloudwatchlogs"]["state_file"]) } | ||
end | ||
end | ||
|
||
service "awslogs" do | ||
supports :status => true, :restart => true | ||
action [:enable, :start] | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
service "awslogs" do | ||
action :stop | ||
end | ||
|
||
directory node["cloudwatchlogs"]["home_dir"] do | ||
action :delete | ||
recursive true | ||
end | ||
|
||
if platform?("amazon") | ||
package "awslogs" do | ||
action :remove | ||
end | ||
else | ||
directory "/opt/aws/cloudwatch" do | ||
action :delete | ||
recursive true | ||
end | ||
|
||
file "/etc/init.d/awslogs" do | ||
action :delete | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[plugins] | ||
cwlogs = cwlogs | ||
[default] | ||
region = <%= @region %> |
14 changes: 14 additions & 0 deletions
14
opsworks_cloudwatchlogs/templates/default/awslogs.conf.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[general] | ||
state_file = <%= @state_file %> | ||
|
||
<% @cloudwatchlogs.each do |layer_name, layer_logs| %> | ||
<% layer_logs.each do |log| %> | ||
[<%= layer_name %> <%= log["file"] %>] | ||
datetime_format = [%Y-%m-%d %H:%M:%S] | ||
log_group_name = <%= layer_name %> | ||
log_stream_name = <%= @hostname %> - <%= log["file"] %> | ||
initial_position = start_of_file | ||
file = <%= log["file"] %> | ||
|
||
<% end %> | ||
<% end %> |