Skip to content

Commit

Permalink
Merge pull request #14107 from jrafanie/add_remote_servers_to_evm_status
Browse files Browse the repository at this point in the history
Add remote servers to rake evm:status_full
  • Loading branch information
Fryguy authored Mar 1, 2017
2 parents 7d9308b + f9fe840 commit 54b9807
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
5 changes: 5 additions & 0 deletions lib/tasks/evm.rake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ namespace :evm do
EvmApplication.status
end

desc "Report Status of the ManageIQ EVM Application"
task :status_full => :environment do
EvmApplication.status(true)
end

desc "Write a remote region id to this server's REGION file"
task :join_region => :environment do
configured_region = ApplicationRecord.region_number_from_sequence.to_i
Expand Down
54 changes: 36 additions & 18 deletions lib/tasks/evm_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,27 @@ def self.server_state
:no_db if error.message =~ /Connection refused/i
end

def self.status
def self.status(include_remotes = false)
puts "Checking EVM status..."

server = MiqServer.my_server(true)
if server.nil?
servers = Set.new
servers << server if server
if include_remotes
all_servers =
MiqServer
.order(:zone_id, :status)
.includes(:active_roles, :miq_workers, :zone)
.all.to_a
servers.merge(all_servers)
end

if servers.empty?
puts "Local EVM Server not Found"
else
output_servers_status([server])
output_servers_status(servers)
puts "\n"
output_workers_status(server.miq_workers)
output_workers_status(servers)
end
end

Expand All @@ -69,26 +81,32 @@ def self.output_servers_status(servers)
s.drb_uri,
s.started_on && s.started_on.iso8601,
s.last_heartbeat && s.last_heartbeat.iso8601,
s.active_role_names.join(':')
s.is_master,
s.active_role_names.join(':'),
]
end
header = ["Zone", "Server Name", "Status", "ID", "PID", "SPID", "URL", "Started On", "Last Heartbeat", "Active Roles"]
header = ["Zone", "Server", "Status", "ID", "PID", "SPID", "URL", "Started On", "Last Heartbeat", "Master?", "Active Roles"]
puts data.unshift(header).tableize
end

def self.output_workers_status(workers)
data = workers.sort_by(&:type).collect do |w|
[w.type,
w.status,
w.id,
w.pid,
w.sql_spid,
w.queue_name || w.uri,
w.started_on && w.started_on.iso8601,
w.last_heartbeat && w.last_heartbeat.iso8601
]
def self.output_workers_status(servers)
data = []
servers.each do |s|
s.miq_workers.order(:type).each do |w|
data <<
[w.type,
w.status,
w.id,
w.pid,
w.sql_spid,
w.miq_server_id,
w.queue_name || w.uri,
w.started_on && w.started_on.iso8601,
w.last_heartbeat && w.last_heartbeat.iso8601]
end
end
header = ["Worker Type", "Status", "ID", "PID", "SPID", "Queue Name / URL", "Started On", "Last Heartbeat"]

header = ["Worker Type", "Status", "ID", "PID", "SPID", "Server id", "Queue Name / URL", "Started On", "Last Heartbeat"]
puts data.unshift(header).tableize unless data.empty?
end

Expand Down

0 comments on commit 54b9807

Please sign in to comment.