57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/cdn_manager_pcache_probe/cli.rb', line 57
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[:api_base_url]
RestClient.log = STDOUT if options[:debug]
begin
RestClient.post(
File.join(options[:api_base_url], "services", options[:service_name], "metrics", options[:metric_name], usage.round(0).to_s),
params: { key: options[:api_key] }
)
rescue => e
say "Error posting metric: #{e.message}", :red
end
end
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
|