#!/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