Sha256: c9b4c07c8c7ae7c5924351d28debc656bce413d928515b9453ac46d12d1638ff

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

module RestFtpDaemon
  module API
    class Root < Grape::API

####### DASHBOARD - GET /

      # Server global status
      get '/' do
        info "GET /"

        # Initialize UsageWatch
        Facter.loadfacts
        @info_load = Sys::CPU.load_avg.first.to_f
        @info_procs = (Facter.value :processorcount).to_i
        @info_ipaddr = Facter.value(:ipaddress)
        @info_memfree = Facter.value(:memoryfree)

        # Compute normalized load
        if @info_procs.zero?
          @info_norm = "N/A"
        else
          @info_norm = (100 * @info_load / @info_procs).round(1)
        end

        # Jobs to display
        popped_jobs = $queue.ordered_popped.reverse
        @jobs_queued = $queue.ordered_queue.reverse

        if params["only"].nil? || params["only"].blank?
          @only = nil
        else
          @only = params["only"].to_sym
        end

        case @only
        when nil
          @jobs_current = popped_jobs
        when :queued
          @jobs_current = @jobs_queued
        else
          @jobs_current = $queue.popped_reverse_sorted_by_status @only
        end

        # Count jobs for each status and total
        @counts = $queue.counts_by_status
        @count_all = $queue.all_size

        # Get workers status
        @gworker_statuses = $pool.get_worker_statuses

        # Compile haml template
        output = render :dashboard

        # Send response
        env['api.format'] = :html
        format "html"
        status 200
        content_type "text/html"
        body output
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.103.1 lib/rest-ftp-daemon/api/dashboard.rb
rest-ftp-daemon-0.101 lib/rest-ftp-daemon/api/dashboard.rb
rest-ftp-daemon-0.100.2 lib/rest-ftp-daemon/api/dashboard.rb
rest-ftp-daemon-0.100 lib/rest-ftp-daemon/api/dashboard.rb