Sha256: 8d58dcc5f1586cca69dbe1da1eaa3e14581a3b27cf81378694416c6604363327

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby

require "rubygems"
require "bundler/setup"

require 'optparse'
require "simple_metrics"

options = {
	:host        => 'localhost',
	:port        => 8125,
	:sample_rate => 1
}

parser ||= OptionParser.new do |opts|
  opts.banner = "Usage Example: simple_metrics_send com.test.mymetric -c5"

  opts.separator ""
  opts.separator "Client options:"

  opts.on("-c", "--counter VALUE", "Counter, a relative value") do |value|
  	options[:type] = 'c'
  	options[:stat] = value.to_i
  end
  opts.on("-g", "--gauge VALUE", "Gauge, an absolute value ") do |value|
  	options[:type] = 'g'
  	options[:stat] = value.to_i
  end
  opts.on("-t", "--timing VALUE", "A timing in ms") do |value|
  	options[:type] = 'ms'
  	options[:stat] = value.to_i
  end
  opts.on("-s", "--sample_rate VALUE", "An optional sample rate between 0 and 1 (example: 0.2)") do |value|
  	options[:sample_rate] = value.to_f || 1
  end

  opts.separator ""

  opts.on("-a", "--address HOST", "bind to HOST address (default: #{options[:host]})") do |host| 
  	options[:host] = host
  end

  opts.on("-p", "--port PORT", "use PORT (default: #{options[:port]})") do |port|
  	options[:port] = port.to_i
  end

  opts.separator ""
  opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
  opts.on_tail('-v', '--version', "Show version") { puts SimpleMetrics::VERSION; exit }

end.parse!(ARGV)

command    = ARGV.shift
arguments  = ARGV
client = SimpleMetrics::Client.new(options[:host])

case options[:type]
when'c' 
	client.count(command, options[:stat], options[:sample_rate])
when 'g'
	client.gauge(command, options[:stat], options[:sample_rate])
when 'ms'
	client.timing(command, options[:stat], options[:sample_rate])
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple_metrics-0.4.0 bin/simple_metrics_client
simple_metrics-0.2.3 bin/simple_metrics_client
simple_metrics-0.2.2 bin/simple_metrics_client
simple_metrics-0.0.1 bin/simple_metrics_client