cwlog_tail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +84 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +55 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/cwlog_tail.gemspec +27 -0
- data/exe/cwlog_tail +3 -0
- data/lib/cwlog_tail/cw_client.rb +63 -0
- data/lib/cwlog_tail/version.rb +3 -0
- data/lib/cwlog_tail.rb +42 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7416170f5e17d7d1d8fb2857504a3484924c2d37
|
4
|
+
data.tar.gz: b8aef91a8605e8ca27f1906aa04473e52e23a6bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee5408cc5858692fb94cdc9e90c0999a1a1c0762ba870d1a4d39cae5fdf7a0b105cd9b1897e8db05f0c3ff392c2c7bba6c2dd910c4c1030158464a31089fed67
|
7
|
+
data.tar.gz: 47250ef816e90e0df7c7e445dbf9d56261116a29a63fc7378d4ce4e4a760ebf43ea8e2a13a2ec232f29289ea454356566eaa236bf6594babf3de4e4dc2f0cfc6
|
data/.gitignore
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
### https://raw.github.com/github/gitignore/f2ce448f2ba7a092da05482ceca99209127c0884/Global/macOS.gitignore
|
2
|
+
|
3
|
+
*.DS_Store
|
4
|
+
.AppleDouble
|
5
|
+
.LSOverride
|
6
|
+
|
7
|
+
# Icon must end with two \r
|
8
|
+
Icon
|
9
|
+
|
10
|
+
|
11
|
+
# Thumbnails
|
12
|
+
._*
|
13
|
+
|
14
|
+
# Files that might appear in the root of a volume
|
15
|
+
.DocumentRevisions-V100
|
16
|
+
.fseventsd
|
17
|
+
.Spotlight-V100
|
18
|
+
.TemporaryItems
|
19
|
+
.Trashes
|
20
|
+
.VolumeIcon.icns
|
21
|
+
.com.apple.timemachine.donotpresent
|
22
|
+
|
23
|
+
# Directories potentially created on remote AFP share
|
24
|
+
.AppleDB
|
25
|
+
.AppleDesktop
|
26
|
+
Network Trash Folder
|
27
|
+
Temporary Items
|
28
|
+
.apdisk
|
29
|
+
|
30
|
+
|
31
|
+
### https://raw.github.com/github/gitignore/f2ce448f2ba7a092da05482ceca99209127c0884/Ruby.gitignore
|
32
|
+
|
33
|
+
*.gem
|
34
|
+
*.rbc
|
35
|
+
/.config
|
36
|
+
/coverage/
|
37
|
+
/InstalledFiles
|
38
|
+
/pkg/
|
39
|
+
/spec/reports/
|
40
|
+
/spec/examples.txt
|
41
|
+
/test/tmp/
|
42
|
+
/test/version_tmp/
|
43
|
+
/tmp/
|
44
|
+
|
45
|
+
# Used by dotenv library to load environment variables.
|
46
|
+
# .env
|
47
|
+
|
48
|
+
## Specific to RubyMotion:
|
49
|
+
.dat*
|
50
|
+
.repl_history
|
51
|
+
build/
|
52
|
+
*.bridgesupport
|
53
|
+
build-iPhoneOS/
|
54
|
+
build-iPhoneSimulator/
|
55
|
+
|
56
|
+
## Specific to RubyMotion (use of CocoaPods):
|
57
|
+
#
|
58
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
59
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
60
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
61
|
+
#
|
62
|
+
# vendor/Pods/
|
63
|
+
|
64
|
+
## Documentation cache and generated files:
|
65
|
+
/.yardoc/
|
66
|
+
/_yardoc/
|
67
|
+
/doc/
|
68
|
+
/rdoc/
|
69
|
+
|
70
|
+
## Environment normalization:
|
71
|
+
/.bundle/
|
72
|
+
/vendor/bundle
|
73
|
+
/lib/bundler/man/
|
74
|
+
|
75
|
+
# for a library or gem, you might want to ignore these files since the code is
|
76
|
+
# intended to run in multiple environments; otherwise, check them in:
|
77
|
+
# Gemfile.lock
|
78
|
+
# .ruby-version
|
79
|
+
# .ruby-gemset
|
80
|
+
|
81
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
82
|
+
.rvmrc
|
83
|
+
|
84
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cwlog_tail (0.0.1)
|
5
|
+
aws-sdk (~> 2.8)
|
6
|
+
peco_selector (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-sdk (2.8.4)
|
12
|
+
aws-sdk-resources (= 2.8.4)
|
13
|
+
aws-sdk-core (2.8.4)
|
14
|
+
aws-sigv4 (~> 1.0)
|
15
|
+
jmespath (~> 1.0)
|
16
|
+
aws-sdk-resources (2.8.4)
|
17
|
+
aws-sdk-core (= 2.8.4)
|
18
|
+
aws-sigv4 (1.0.0)
|
19
|
+
coderay (1.1.1)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
jmespath (1.3.1)
|
22
|
+
method_source (0.8.2)
|
23
|
+
peco_selector (1.0.0)
|
24
|
+
pry (0.10.4)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.8.1)
|
27
|
+
slop (~> 3.4)
|
28
|
+
rake (10.5.0)
|
29
|
+
rspec (3.5.0)
|
30
|
+
rspec-core (~> 3.5.0)
|
31
|
+
rspec-expectations (~> 3.5.0)
|
32
|
+
rspec-mocks (~> 3.5.0)
|
33
|
+
rspec-core (3.5.4)
|
34
|
+
rspec-support (~> 3.5.0)
|
35
|
+
rspec-expectations (3.5.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.5.0)
|
38
|
+
rspec-mocks (3.5.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.5.0)
|
41
|
+
rspec-support (3.5.0)
|
42
|
+
slop (3.6.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 1.12)
|
49
|
+
cwlog_tail!
|
50
|
+
pry
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
1.13.7
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
cwlog_tail
|
2
|
+
===============
|
3
|
+
|
4
|
+
tail AWS CloudWatch logs on terminal
|
5
|
+
|
6
|
+
# License
|
7
|
+
|
8
|
+
```
|
9
|
+
The MIT License (MIT)
|
10
|
+
|
11
|
+
Copyright (c) 2017 Tomoki Yamashita
|
12
|
+
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
15
|
+
in the Software without restriction, including without limitation the rights
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
18
|
+
furnished to do so, subject to the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be included in
|
21
|
+
all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
29
|
+
THE SOFTWARE.
|
30
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/cwlog_tail.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'cwlog_tail/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'cwlog_tail'
|
7
|
+
spec.version = CwlogTail::VERSION
|
8
|
+
spec.authors = ['Tomoki Yamashita']
|
9
|
+
spec.email = ['tomorrowkey@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q{Tail CloudWatch log}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'http://github.com/tomorrowkey/cwlog_tail'
|
14
|
+
spec.license = 'Apache License 2.0'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'aws-sdk', '~> 2.8'
|
22
|
+
spec.add_dependency 'peco_selector', '~> 1.0'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
end
|
data/exe/cwlog_tail
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module CwlogTail
|
4
|
+
class CwClient
|
5
|
+
TAIL_INTERVAL = 5
|
6
|
+
DEFAULT_LINES = 100
|
7
|
+
DEFAULT_PAGE_COUNT = 3
|
8
|
+
|
9
|
+
def client
|
10
|
+
@cloudwatch ||= Aws::CloudWatchLogs::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def log_groups
|
14
|
+
client.describe_log_groups.log_groups
|
15
|
+
end
|
16
|
+
|
17
|
+
def log_group_names
|
18
|
+
log_groups.map(&:log_group_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def log_streams(log_group_name, page_count = DEFAULT_PAGE_COUNT)
|
22
|
+
next_token = nil
|
23
|
+
@log_streams ||= page_count.times.each.with_object([]) { |_, results|
|
24
|
+
log_streams = client.describe_log_streams(
|
25
|
+
log_group_name: log_group_name,
|
26
|
+
order_by: :LastEventTime,
|
27
|
+
descending: true,
|
28
|
+
next_token: next_token)
|
29
|
+
results << log_streams.log_streams
|
30
|
+
next_token = log_streams.next_token
|
31
|
+
}.flatten
|
32
|
+
end
|
33
|
+
|
34
|
+
def tail_stream(log_group_name, log_stream_name, options)
|
35
|
+
last_token = nil
|
36
|
+
loop do
|
37
|
+
log_options = {
|
38
|
+
log_group_name: log_group_name,
|
39
|
+
log_stream_name: log_stream_name,
|
40
|
+
next_token: last_token
|
41
|
+
}
|
42
|
+
if options[:lines].nil?
|
43
|
+
log_options[:start_from_head] = true
|
44
|
+
log_options[:limit] = DEFAULT_LINES
|
45
|
+
else
|
46
|
+
log_options[:start_from_head] = false
|
47
|
+
log_options[:limit] = options[:lines]
|
48
|
+
end
|
49
|
+
pages = client.get_log_events(log_options)
|
50
|
+
pages.events.each { |event| yield(event) }
|
51
|
+
|
52
|
+
if last_token == pages.next_forward_token
|
53
|
+
if options[:follow]
|
54
|
+
sleep TAIL_INTERVAL
|
55
|
+
else
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
last_token = pages.next_forward_token
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/cwlog_tail.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'cwlog_tail/version'
|
2
|
+
require 'cwlog_tail/cw_client'
|
3
|
+
require 'peco_selector'
|
4
|
+
|
5
|
+
module CwlogTail
|
6
|
+
def self.follow?
|
7
|
+
ARGV.member?('-f')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.lines
|
11
|
+
idx = ARGV.index('-l') || ARGV.index('--lines')
|
12
|
+
if idx.nil?
|
13
|
+
nil
|
14
|
+
else
|
15
|
+
ARGV[idx + 1].to_i
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.options
|
20
|
+
{ follow: follow?,
|
21
|
+
lines: lines,
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
client = CwClient.new
|
26
|
+
|
27
|
+
log_group_name = PecoSelector.select_from(client.log_group_names).first
|
28
|
+
exit 0 unless log_group_name
|
29
|
+
|
30
|
+
log_stream_name = PecoSelector.select_from(client.log_streams(log_group_name).map{|log_stream|
|
31
|
+
["#{Time.at(log_stream.last_event_timestamp / 1000)} #{log_stream.log_stream_name}", log_stream]
|
32
|
+
}).first&.log_stream_name
|
33
|
+
exit 0 unless log_stream_name
|
34
|
+
|
35
|
+
begin
|
36
|
+
client.tail_stream(log_group_name, log_stream_name, options) do |event|
|
37
|
+
puts "[#{Time.at(event.timestamp / 1000)}] #{event.message}"
|
38
|
+
end
|
39
|
+
rescue Interrupt
|
40
|
+
puts ''
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cwlog_tail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomoki Yamashita
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: peco_selector
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Tail CloudWatch log
|
98
|
+
email:
|
99
|
+
- tomorrowkey@gmail.com
|
100
|
+
executables:
|
101
|
+
- cwlog_tail
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- cwlog_tail.gemspec
|
112
|
+
- exe/cwlog_tail
|
113
|
+
- lib/cwlog_tail.rb
|
114
|
+
- lib/cwlog_tail/cw_client.rb
|
115
|
+
- lib/cwlog_tail/version.rb
|
116
|
+
homepage: http://github.com/tomorrowkey/cwlog_tail
|
117
|
+
licenses:
|
118
|
+
- Apache License 2.0
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.6.8
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Tail CloudWatch log
|
140
|
+
test_files: []
|