cwlogs-s3 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -12
- data/bin/cwlogs-s3 +2 -3
- data/cwlogs-s3.gemspec +1 -1
- data/lib/cwlogs-s3/command.rb +7 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -1,30 +1,54 @@
|
|
1
|
-
#
|
1
|
+
# cwlogs-s3
|
2
2
|
|
3
|
-
|
3
|
+
Task for exporting CloudWatch logs to S3. Useful for then running logs through EMR for analysis. Designed to be run
|
4
|
+
via AWS Data Pipeline.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
|
-
|
8
|
+
$ gem install cwlogs-s3
|
9
|
+
|
10
|
+
## Usage
|
8
11
|
|
9
|
-
```
|
10
|
-
|
12
|
+
```
|
13
|
+
NAME
|
14
|
+
cwlogs-s3 -
|
15
|
+
|
16
|
+
USAGE
|
17
|
+
cwlogs-s3 [options] [arguments]
|
18
|
+
|
19
|
+
OPTIONS
|
20
|
+
--group -g <s> - Log group name
|
21
|
+
- Log group is required
|
22
|
+
--period -p <s> - Period to export (default: 1 day)
|
23
|
+
- Cannot parse period
|
24
|
+
--ending -e <s> - Time when period ends (default: now)
|
25
|
+
- Cannot parse ending
|
26
|
+
--s3path -s <s> - Destination S3 path
|
27
|
+
- S3 path is required
|
28
|
+
--region -r <s> - AWS region (default: us-east-1)
|
29
|
+
--verbosity <s> - Verbosity level of output for current execution
|
30
|
+
(e.g. INFO, DEBUG) (default: WARN)
|
31
|
+
--error-output-format <s - The format to use when outputting errors (e.g. b
|
32
|
+
> asic, advanced) (default: basic)
|
33
|
+
--help -h - Show this messag
|
11
34
|
```
|
12
35
|
|
13
|
-
|
36
|
+
For example:
|
14
37
|
|
15
|
-
|
38
|
+
```
|
39
|
+
cwlogs-s3 -g "my-app-http-access" -p "3 days" -e "now" -s "s3://mybucket/mypath/"
|
40
|
+
```
|
16
41
|
|
17
|
-
|
42
|
+
Which will export all logs in the `my-app-http-access` from the last 3 days ending now to a bucket called `my-log-bucket`.
|
18
43
|
|
19
|
-
$ gem install cwlogs-s3
|
20
44
|
|
21
|
-
|
45
|
+
`--period` Can be formatted according to Chronic Duration: https://github.com/hpoydar/chronic_duration
|
22
46
|
|
23
|
-
|
47
|
+
`--ending` Can be formatted according to Chronic: https://github.com/mojombo/chronic
|
24
48
|
|
25
49
|
## Contributing
|
26
50
|
|
27
|
-
1. Fork it ( https://github.com/
|
51
|
+
1. Fork it ( https://github.com/Tim-B/cwlogs-s3/fork )
|
28
52
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
53
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
54
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/cwlogs-s3
CHANGED
@@ -12,14 +12,13 @@ Escort::App.create do |app|
|
|
12
12
|
opts.opt :group, 'Log group name', :short => '-g', :long => '--group', :type => :string, default: nil
|
13
13
|
opts.opt :period, 'Period to export', :short => '-p', :long => '--period', :type => :string, default: '1 day'
|
14
14
|
opts.opt :ending, 'Time when period ends', :short => '-e', :long => '--ending', :type => :string, default: 'now'
|
15
|
-
opts.opt :
|
16
|
-
opts.opt :prefix, 'Prefix', :short => '-f', :long => '--prefix', :type => :string, default: 'logs/'
|
15
|
+
opts.opt :s3_path, 'Destination S3 path', :short => '-s', :long => '--s3path', :type => :string, default: nil
|
17
16
|
opts.opt :region, 'AWS region', :short => '-r', :long => '--region', :type => :string, default: 'us-east-1'
|
18
17
|
|
19
18
|
opts.validate(:period, 'Cannot parse period') { |option| ChronicDuration.parse(option) != nil }
|
20
19
|
opts.validate(:ending, 'Cannot parse ending') { |option| Chronic.parse(option) != nil }
|
21
20
|
opts.validate(:group, 'Log group is required') { |option| option != nil }
|
22
|
-
opts.validate(:
|
21
|
+
opts.validate(:s3_path, 'S3 path is required') { |option| option != nil }
|
23
22
|
end
|
24
23
|
|
25
24
|
app.action do |options, arguments|
|
data/cwlogs-s3.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "cwlogs-s3"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.4'
|
8
8
|
spec.authors = ["Tim-B"]
|
9
9
|
spec.email = ["tim@galacticcode.com"]
|
10
10
|
spec.summary = %q{Exports logs from CloudWatch logs and uploads them to S3}
|
data/lib/cwlogs-s3/command.rb
CHANGED
@@ -3,6 +3,7 @@ require 'chronic'
|
|
3
3
|
require 'chronic_duration'
|
4
4
|
require 'aws-sdk'
|
5
5
|
require 'securerandom'
|
6
|
+
require 'uri'
|
6
7
|
|
7
8
|
module CWLogsToS3
|
8
9
|
|
@@ -17,6 +18,10 @@ module CWLogsToS3
|
|
17
18
|
period = ChronicDuration.parse(command_options[:period])
|
18
19
|
start = Time.at(ending.to_i - period)
|
19
20
|
|
21
|
+
s3Uri = URI(command_options[:s3_path])
|
22
|
+
@bucket = s3Uri.host
|
23
|
+
@s3_prefix = s3Uri.path.gsub!(/^\//, '')
|
24
|
+
|
20
25
|
Escort::Logger.output.puts "Exporting from #{start} to #{ending}"
|
21
26
|
|
22
27
|
@cwl = Aws::CloudWatchLogs::Client.new(region: command_options[:region])
|
@@ -64,8 +69,8 @@ module CWLogsToS3
|
|
64
69
|
@event_cnt = @event_cnt + 1
|
65
70
|
page_content << event[:message] << "\n"
|
66
71
|
end
|
67
|
-
object_name =
|
68
|
-
@s3.bucket(
|
72
|
+
object_name = @s3_prefix + randomise_prefix + '_' + @page_cnt.to_s + '.log'
|
73
|
+
@s3.bucket(@bucket).object(object_name).put(
|
69
74
|
:body => page_content
|
70
75
|
)
|
71
76
|
Escort::Logger.output.puts "Put #{object_name} to S3."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cwlogs-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|