Class: Awful::CloudWatchLogs
- Inherits:
-
Cli
show all
- Defined in:
- lib/awful/cloudwatch_logs.rb
Instance Method Summary
collapse
Methods inherited from Cli
#initialize
Constructor Details
This class inherits a constructor from Awful::Cli
Instance Method Details
#create(name) ⇒ Object
45
46
47
|
# File 'lib/awful/cloudwatch_logs.rb', line 45
def create(name)
logs.create_log_group(log_group_name: name)
end
|
#delete(name) ⇒ Object
50
51
52
|
# File 'lib/awful/cloudwatch_logs.rb', line 50
def delete(name)
logs.delete_log_group(log_group_name: name)
end
|
#events(group, nth = 0) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/awful/cloudwatch_logs.rb', line 113
def events(group, nth = 0)
opt = options.dup
opt[:stream] ||= latest_stream(group, nth).log_stream_name
if opt[:tail]
opt[:head] = false
opt[:pages] = 1
opt[:limit] = opt[:tail]
end
next_token = nil
events = []
pages = 0
loop do
response = logs.get_log_events(
log_group_name: group,
log_stream_name: opt[:stream],
start_from_head: opt[:head],
limit: opt[:limit],
next_token: next_token,
)
break if response.events.count == 0 events = events + response.events
pages += 1
break if pages >= opt[:pages]
next_token = response.next_backward_token
break if next_token.nil? end
events.output do |ev|
if options[:long]
print_table ev.map { |e| [Time.at(e.timestamp.to_i/1000), e.message] }
else
puts ev.map(&:message)
end
end
end
|
#latest(group, n = 0) ⇒ Object
100
101
102
103
104
|
# File 'lib/awful/cloudwatch_logs.rb', line 100
def latest(group, n = 0)
latest_stream(group, n).output do |stream|
puts stream.log_stream_name
end
end
|
#ls(prefix = nil) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/awful/cloudwatch_logs.rb', line 17
def ls(prefix = nil)
next_token = nil
log_groups = []
loop do
response = logs.describe_log_groups(log_group_name_prefix: prefix, next_token: next_token)
log_groups = log_groups + response.log_groups
next_token = response.next_token
break if next_token.nil?
end
log_groups.output do |groups|
if options[:long]
print_table groups.map { |group|
[
group.log_group_name,
group.retention_in_days,
Time.at(group.creation_time.to_i/1000),
group.stored_bytes,
]
}
else
puts groups.map(&:log_group_name)
end
end
end
|
#streams(group, prefix = nil) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/awful/cloudwatch_logs.rb', line 58
def streams(group, prefix = nil)
next_token = nil
log_streams = []
loop do
response = logs.describe_log_streams(
log_group_name: group,
log_stream_name_prefix: prefix,
order_by: options[:alpha] ? 'LogStreamName' : 'LastEventTime',
descending: (not options[:alpha]), limit: options[:limit],
next_token: next_token
)
log_streams = log_streams + response.log_streams
next_token = response.next_token
break if next_token.nil?
break if log_streams.count >= options[:limit].to_i
end
log_streams.output do |streams|
if options[:long]
print_table streams.map { |s|
[ s.log_stream_name, Time.at(s.creation_time.to_i/1000), Time.at(s.last_event_timestamp.to_i/1000) ]
}
else
puts streams.map(&:log_stream_name)
end
end
end
|