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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/jcf/cli/commands/cf/metrics.rb', line 31
def call(*_args, **options)
validate_options(options)
JCF.plugin options[:iaas_plugin].to_sym
plugin = JCF::Plugins.plugins[options[:iaas_plugin].to_sym]
orgs = options[:org].include?(",") ? options[:org].split(",") : [options[:org]]
brokers = service_brokers.select { |b| b.name == options[:broker] }
offerings = service_offerings.select do |o|
brokers.find { |b| b.guid == o.relationships.service_broker.guid }
end
if offerings && offerings.empty?
err.puts "No offerings found for broker #{options[:broker]}"
exit(1)
end
err.puts "Found #{offerings.count} offerings"
orgs.each do |org|
org_guid = organizations.find { |o| o.name == org }.guid
err.puts "Found org guid: #{org_guid}"
plan_guids = service_plans.find_all do |plan|
offerings.collect(&:guid).include? plan.relationships.service_offering.guid
end.collect(&:guid)
err.puts "Found plan guids: #{plan_guids.count}"
if plan_guids.empty?
err.puts "No plans found for offerings"
exit(1)
end
instances = JCF::CF::ServiceInstance.all(
organization_guids: org_guid,
service_plan_guids: plan_guids.join(",")
)
instances.select! { |i| i.name.include? options[:name] } if options[:name]
err.puts "Found instances: #{instances.count}"
values = {}
Thread.abort_on_exception = true
instances.each_slice(Concurrent.processor_count) do |slice|
slice.collect do |instance|
service_plan = instance.relationships.service_plan.populate!
service_offering = service_plan.relationships.service_offering.populate!
service_broker = service_offering.relationships.service_broker.populate!
Thread.new do
metrics = {}
metrics[:name] = (instance.name || "")
metrics[:instance_guid] = instance.guid
err.puts "Getting metrics for #{instance.name}"
metrics[:region] = ENV["AWS_REGION"]
metrics[:organization] = org
metrics[:organization_guid] = org_guid
space = spaces.find { |s| s.guid == instance.relationships.space.guid }
metrics[:space] = space.name
metrics[:space_guid] = space.guid
metrics[:service_broker_name] = service_broker.name
metrics[:service_broker_guid] = service_broker.guid
metrics[:service_offering] = service_offering.name
metrics[:service_plan] = service_plan.name
template = options[:template]
t_values = parse_values(options[:values], instance.guid)
t = JCF::CLI.template_parser(template, t_values)
plugin.new(name: t).metrics.each do |k, v|
metrics[k] = v
end
values[instance.guid] = metrics
end
end.each(&:join)
end
output = Hash.new { |hash, key| hash[key] = [] }
values.each do |guid, metrics|
metrics.each do |k, v|
output[k] << v
end
end
out.puts formatter.format(data: output)
err.puts "Done."
end
end
|