Class: CdnManagerPcacheProbe::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/cdn_manager_pcache_probe/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

exit with return code 1 in case of an error

Returns:

  • (Boolean)


17
18
19
# File 'lib/cdn_manager_pcache_probe/cli.rb', line 17

def self.exit_on_failure?
  true
end

Instance Method Details

#collectObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cdn_manager_pcache_probe/cli.rb', line 47

def collect
  bytes_sent = CdnManagerPcacheProbe::Connector.new(
    options[:url]
  ).get_probe(options)

  usage = (bytes_sent / (options[:interval] * 60) * 8 / 1024**2).round(3)
  if options[:quiet]
    puts usage.round(0)
  else
    if options[:key]
      say "Usage for #{options[:key]} ", :yellow
    else
      say "Overall usage ", :yellow
    end
    say "over #{options[:interval]} min (#{options[:delay]} min delay):", :yellow
    puts "Total volume sent: #{(bytes_sent / 1024**3).round(3)} GB"
    print "Average bandwidth: #{usage} Mbit/s"
    puts usage >= 1000 ? " (#{(usage / 1024.0).round(2)} Gbit/s)" : nil
  end
end

#versionObject



22
23
24
# File 'lib/cdn_manager_pcache_probe/cli.rb', line 22

def version
  say "cdn_manager_pcache_probe v#{VERSION}"
end