13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/foreman_statistics/api/v2/statistics_controller.rb', line 13
def index
@os_count = Statistics::CountHosts.new(count_by: :operatingsystem)
@arch_count = Statistics::CountHosts.new(count_by: :architecture)
if defined?(ForemanPuppet)
@env_count = Statistics::CountHosts.new(count_by: :environment)
@klass_count = Statistics::CountPuppetClasses.new(id: :puppetclass)
end
@cpu_count = FactValue.authorized(:view_facts).my_facts.count_each 'processorcount'
@model_count = FactValue.authorized(:view_facts).my_facts.count_each 'manufacturer'
@mem_size = FactValue.authorized(:view_facts).my_facts.mem_average 'memorysize'
@mem_free = FactValue.authorized(:view_facts).my_facts.mem_average 'memoryfree'
@swap_size = FactValue.authorized(:view_facts).my_facts.mem_average 'swapsize'
@swap_free = FactValue.authorized(:view_facts).my_facts.mem_average 'swapfree'
@mem_totsize = FactValue.authorized(:view_facts).my_facts.mem_sum 'memorysize'
@mem_totfree = FactValue.authorized(:view_facts).my_facts.mem_sum 'memoryfree'
render :json => { :os_count => @os_count.calculate, :arch_count => @arch_count.calculate, :swap_size => @swap_size,
:env_count => @env_count&.calculate, :klass_count => @klass_count&.calculate, :cpu_count => @cpu_count,
:model_count => @model_count, :mem_size => @mem_size, :mem_free => @mem_free,
:swap_free => @swap_free, :mem_totsize => @mem_totsize, :mem_totfree => @mem_totfree }
end
|