-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-setup.rb
executable file
·48 lines (40 loc) · 1.22 KB
/
metrics-setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
#!/usr/bin/env ruby
DEFAULT_RC_FILE="/etc/ec2-credentials.rc"
TARGET="/opt/sar-metrics/"
TARGET_TEMPLATE = TARGET + "scaling.template"
TARGET_SCRIPT = TARGET + "metrics-job.rb"
CRON_FILE="/etc/sar-cronjob"
require_relative 'alarm-resource'
require_relative 'heat-watch-client'
def print_usage
puts "Usage: metrics-setup file.template stack-name"
end
if ARGV.size != 2 then
print_usage
exit 1
end
template_file_path = ARGV[0]
alarms = AlarmUtils.collect_alarms_from_template(template_file_path)
stack_name = ARGV[1]
puts "Found alarms: #{alarms}"
puts "Calling heat-watch metric-put-data..."
heat_watch_client = HeatWatchClient.new
alarms.each do |alarm|
heat_watch_client.metric_put_data({
stack_name: stack_name,
alarm_name: alarm.name,
namespace: alarm.namespace,
metric_name: alarm.metric
})
end
puts "Installing sar-metrics"
`mkdir #{TARGET}` unless File.exists?(TARGET)
`cp *.rb #{TARGET}`
`chmod +x #{TARGET_SCRIPT}`
puts "Copying template file..."
`cp #{template_file_path} #{TARGET_TEMPLATE}`
puts "Creating crontab entry..."
`echo "*/1 * * * * source #{DEFAULT_RC_FILE} && #{TARGET_SCRIPT} #{TARGET_TEMPLATE} #{stack_name}" > #{CRON_FILE}`
puts "Reloading crontab..."
`crontab #{CRON_FILE}`
puts "Done."