class Google::Cloud::Gemserver::Backend::Stats

# Stats

Stats provides a set of methods that display detailed information about the deployed gemserver. It includes: general Google Cloud Platform project information, how long the gemserver has been running , what private gems are stored, and what gems have been cached.

Attributes

proj[RW]

The project ID of the project on Google Cloud Platform the gemserver was deployed to. @return [String]

Public Class Methods

new() click to toggle source

Initialize a Configuration object and project ID for the Stats object enabling it to fetch detailed information about the gemserver.

# File lib/google/cloud/gemserver/backend/stats.rb, line 42
def initialize
  @config = Google::Cloud::Gemserver::Configuration.new
  @proj = (@config[:proj_id] || nil).freeze
end

Public Instance Methods

log_app_description() click to toggle source

Displays information about the project on Google Cloud Platform the gemserver was deployed to.

# File lib/google/cloud/gemserver/backend/stats.rb, line 61
def log_app_description
  return "" if ENV["APP_ENV"] == "test"
  puts "Project Information:"
  cmd = "gcloud app describe --project #{@proj}"
  puts run_cmd(cmd).gsub("\n", "\n\t").prepend "\t"
end
run() click to toggle source

Displays various sets of information about the gemserver such as how long it has been running, currently stored, private gems and their status, and cached gems.

# File lib/google/cloud/gemserver/backend/stats.rb, line 51
def run
  resp = ""
  resp << log_uptime
  resp << log_private_gems
  resp << log_cached_gems
end

Private Instance Methods

db(table) click to toggle source

@private Retrieves all the rows in the database for a given table.

@param [String] table The table to be read.

@return [Array]

# File lib/google/cloud/gemserver/backend/stats.rb, line 134
def db table
  env.db[table].all
end
env() click to toggle source

@private Fetches the Environment object currently being used by the gemserver. It enables access to the database.

@return [Gemstash::Env]

# File lib/google/cloud/gemserver/backend/stats.rb, line 124
def env
  GemstashServer.env @config.config_path
end
log_cached_gems() click to toggle source

@private Displays the gems cached on the gemserver.

# File lib/google/cloud/gemserver/backend/stats.rb, line 94
def log_cached_gems
  res = "Cached Gem Dependencies:\n"
  cached = db :cached_rubygems
  format = "%35s\t%20s\n"
  res << sprintf(format, "Gem Name - Version", "Date Cached")
  cached.map do |gem|
    res << sprintf(format, gem[:name], gem[:created_at])
  end
  puts res
  res
end
log_private_gems() click to toggle source

@private Displays the private gems stored on the gemserver and their status (currently indexed or not).

# File lib/google/cloud/gemserver/backend/stats.rb, line 80
def log_private_gems
  res = "Private Gems:\n"
  versions = db :versions
  format = "%35s\t%20s\n"
  res << sprintf(format, "Gem Name - Version", "Available?")
  versions.map do |gem|
    res << sprintf(format, gem[:storage_id], gem[:indexed])
  end
  puts res
  res
end
log_uptime() click to toggle source

@private Displays the time of which the gemserver was deployed.

# File lib/google/cloud/gemserver/backend/stats.rb, line 72
def log_uptime
  return "" unless project
  "The gemserver has been running since #{project.created_at}\n"
end
project() click to toggle source

@private Fetches the Google Cloud Platform project the gemserver was deployed to.

@return [Project]

# File lib/google/cloud/gemserver/backend/stats.rb, line 111
def project
  if @proj.nil?
    return nil if ENV["APP_ENV"] == "test"
    raise ":proj_id not set in config file"
  end
  Google::Cloud::Gemserver::CLI::Project.new(@proj).send(:project)
end
run_cmd(cmd) click to toggle source

@private Runs a given command on the local machine.

@param [String] cmd The command to be run.

# File lib/google/cloud/gemserver/backend/stats.rb, line 142
def run_cmd cmd
  `#{cmd}`
end