25
26
27
28
29
30
31
32
33
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
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
85
86
87
|
# File 'lib/new_relic/ia/cli.rb', line 25
def execute(stdout, arguments=[])
log.level = Logger::INFO
@aspects = []
parser = OptionParser.new do |opts|
opts.banner = <<-BANNER.gsub(/^ */,'')
New Relic Infrastructure Agent (IA) version #{NewRelic::IA::VERSION}
Monitor different aspects of your environment with New Relic RPM.
Usage: #{File.basename($0)} [ options ] aspect, aspect..
aspect: one or more of 'memcached', 'iostat' or 'disk' (more to come)
BANNER
opts.separator ""
opts.on("-a", "--all",
"use all available aspects") { @aspects = %w[iostat disk memcached] }
opts.on("-v", "--verbose",
"debug output") { NewRelic::IA::CLI.log.level = Logger::DEBUG }
opts.on("-q", "--quiet",
"quiet output") { NewRelic::IA::CLI.log.level = Logger::ERROR }
opts.on("-e", "--environment=ENV",
"use ENV section in newrelic.yml") { |e| @env = e }
opts.on("--install license_key",
"create a default newrelic.yml") { |key| return self.install(key, stdout) }
opts.on("-h", "--help",
"Show this help message.") { stdout.puts "#{opts}\n"; return 0 }
begin
args = opts.parse! arguments
unless args.empty?
@aspects = args
end
rescue => e
stdout.puts e
stdout.puts opts
return 1
end
end
@aspects.delete_if do |aspect|
unless self.instance_methods(false).include? aspect
stdout.puts "Unknown aspect: #{aspect}"
true
end
end
if @aspects.empty?
stdout.puts "No aspects specified."
stdout.puts parser
return 1
end
require_newrelic_rpm
NewRelic::Agent.manual_start :env => @env, :monitor_mode => true, :log => self.log
if not (NewRelic::Agent.instance.connected? rescue true)
raise InitError, "Unable to connect to RPM server. Agent not started."
end
cli = new
@aspects.each do | aspect |
cli.send aspect
end
return nil
rescue InitError => e
stdout.puts e.message
return 1
end
|