class SystemControllerBase
Public Class Methods
new()
click to toggle source
methods
Calls superclass method
# File lib/mrpin/controllers/system_controller_base.rb, line 85 def initialize super end
Public Instance Methods
cleanup_data()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 136 def cleanup_data result = nil begin result = get_response_ok(AppInfo.instance.cleanup_data) rescue Exception => e result = get_response_error(e) end render json: result end
download()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 149 def download begin url = get_url_for_download(params['type']) assert(!url.nil?, "url is not specified for param #{params['type']}") redirect_to(url) rescue Exception => e result = get_response_error(e) render json: result end end
gc_stat()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 68 def gc_stat result = nil begin result = get_response_ok(GC.stat) rescue Exception => e result = get_response_error(e) end render json: result end
generate_client_json()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 189 def generate_client_json call_in_all_managers('generate_client_json') end
info()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 90 def info result = nil begin response = get_system_info result = get_response_ok(response) rescue Exception => e result = get_response_error(e) end render json: result end
invalidate_cache()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 194 def invalidate_cache call_in_all_managers('invalidate_cache') end
send_notifications()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 117 def send_notifications result = nil begin manager_notifications = AppInfo.instance.manager_notifications unless manager_notifications.nil? manager_notifications.send_notifications end result = get_response_ok rescue Exception => e result = get_response_error(e) end render json: result end
Protected Instance Methods
available_disk_space()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 50 def available_disk_space begin %x{df -h /}.lines.to_a rescue #do nothing end end
get_system_info()
click to toggle source
properties
# File lib/mrpin/controllers/system_controller_base.rb, line 13 def get_system_info cpu_load = Vmstat.load_average.to_h cpu_load.each do |key, value| cpu_load[key] = value.round(2) end result = { environment: Rails.env, system: { 'memory, MB'.to_sym => { task: self.memory_task, free: Vmstat.memory.free_bytes/1024/1024, total: Vmstat.memory.total_bytes/1024/1024, }, cpu_load: cpu_load, server_up_time: get_time(Vmstat.boot_time), application_up_time: get_time(AppInfo.instance.boot_time) }, sdk_version: Gem.loaded_specs['mrpin-sdk'].version.to_s, available_disk_space: self.available_disk_space, ruby_version: "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } manager_remote = AppInfo.instance.managers_list.detect { |manager| manager.is_a?(ManagerRemoteSocketBase) } unless manager_remote.nil? result[:open_sessions] = manager_remote.sessions.size result[:requests_pending] = manager_remote.requests_pending end result end
memory_task()
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 59 def memory_task begin `ps -o rss -p #{Process::pid}`.chomp.split("\n").last.strip.to_i/1024 rescue #do nothing end end
Private Instance Methods
authenticated_url(key, bucket_name, expires_in = 1.hour)
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 181 def authenticated_url(key, bucket_name, expires_in = 1.hour) #todo:review # s3 = AppInfo.instance.aws_uploader.s3 # object = s3.buckets[bucket_name].objects[key] # object.url_for(:read, expires_in: expires_in).to_s end
call_in_all_managers(method)
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 199 def call_in_all_managers(method) begin errors = AppInfo.instance.call_in_all_managers(method) errors.map!(&:to_s) if errors.empty? result = get_response_ok else result = get_response_error(nil, errors) end rescue Exception => e result = get_response_error(e) end render json: result end
get_time(timestamp)
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 106 def get_time(timestamp) result = nil unless timestamp.nil? result = time_ago_in_words(timestamp.utc) + ', ' + timestamp.utc.to_s end result end
get_url_for_download(type)
click to toggle source
# File lib/mrpin/controllers/system_controller_base.rb, line 166 def get_url_for_download(type) result = nil case type when 'csv' server_name = AppInfo.instance.server_name result = authenticated_url(File.join('csv', server_name, "#{server_name}.zip"), 'mrpin-downloads') else result = nil end result end