Class: DynamoAutoscale::CWPoller
Constant Summary
collapse
- INTERVAL =
5.minutes
Instance Attribute Summary
Attributes inherited from Poller
#filters, #tables
Instance Method Summary
collapse
Methods included from Logger
included, logger, #logger, logger=
Methods inherited from Poller
#dispatch, #initialize, #run
Instance Method Details
#backdate ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dynamo-autoscale/cw_poller.rb', line 6
def backdate
now = Time.now.utc
@tables.each do |table_name|
table = DynamoAutoscale.tables[table_name]
dispatch(table, Metrics.all_metrics(table_name, {
period: 5.minutes,
start_time: now - 6.hours,
end_time: now,
}))
end
end
|
#do_poll(tables, &block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/dynamo-autoscale/cw_poller.rb', line 34
def do_poll tables, &block
logger.debug "[cw_poller] Beginning CloudWatch poll..."
now = Time.now
tables.each do |table_name|
block.call(table_name, Metrics.all_metrics(table_name, {
period: 5.minutes,
start_time: now - 20.minutes,
end_time: now,
}))
end
end
|
#poll(tables, &block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dynamo-autoscale/cw_poller.rb', line 19
def poll tables, &block
tables = AWS::DynamoDB.new.tables.to_a.map(&:name) if tables.nil?
loop do
sleep_duration = INTERVAL - ((Time.now.to_i + INTERVAL) % INTERVAL)
logger.debug "[cw_poller] Sleeping for #{sleep_duration} seconds..."
sleep(sleep_duration)
do_poll(tables, &block)
end
end
|