Permalink
Browse files

moved client to own gem

  • Loading branch information...
Frederik Dietz
Frederik Dietz committed Apr 9, 2012
1 parent 5e766c7 commit a20207cef1a5a5859a07da2403a883d8c329db58
Showing with 0 additions and 117 deletions.
  1. +0 −33 README.markdown
  2. +0 −1 lib/simple_metrics.rb
  3. +0 −83 lib/simple_metrics/client.rb
View
@@ -32,39 +32,6 @@ more info:
simple_metrics_client --help
-Ruby client API
----------------
-
-Initialize client:
-
- client = SimpleMetrics::Client.new("localhost")
-
-sends "com.example.test1:1|c" via UDP:
-
- client.increment("com.example.test1")
-
-sends "com.example.test1:-1|c":
-
- client.decrement("com.example.test1")
-
-sends "com.example.test1:5|c" (a counter with a relative value of 5):
-
- client.count("com.example.test1", 5)
-
-sends "com.example.test1:5|c|@0.1" with a sample rate of 10%:
-
- client.count("com.example.test1", 5, 0.1)
-
-sends "com.example.test1:5|g" (meaning gauge, an absolute value of 5):
-
- client.gauge("com.example.test1", 5)
-
-sends "com.example.test1:100|ms":
-
- client.timing("com.example.test1")
-
-More examples in the examples/ directory.
-
SimpleMetrics Server
--------------------
View
@@ -2,7 +2,6 @@
require "logger"
require "simple_metrics/version"
-require "simple_metrics/client"
require "simple_metrics/udp_server"
require "simple_metrics/data_point_repository"
require "simple_metrics/data_point"
@@ -1,83 +0,0 @@
-# encoding: utf-8
-require "socket"
-
-module SimpleMetrics
-
- class Client
- VERSION = "0.0.1"
-
- def initialize(host, port = 8125)
- @host, @port = host, port
- end
-
- # send relative value
- def increment(stat, sample_rate = 1)
- count(stat, 1, sample_rate)
- end
-
- # send relative value
- def decrement(stat, sample_rate = 1)
- count(stat, -1, sample_rate)
- end
-
- # send relative value
- def count(stat, count, sample_rate = 1)
- send_data( stat, count, 'c', sample_rate)
- end
-
- # send absolute value
- # TODO: check if this is actually supported by Statsd server
- def gauge(stat, value)
- send_data(stat, value, 'g')
- end
-
- # Sends a timing (in ms) (glork)
- def timing(stat, ms, sample_rate = 1)
- send_data(stat, ms, 'ms', sample_rate)
- end
-
- # Sends a timing (in ms) block based
- def time(stat, sample_rate = 1, &block)
- start = Time.now
- result = block.call
- timing(stat, ((Time.now - start) * 1000).round, sample_rate)
- result
- end
-
- private
-
- def sampled(sample_rate, &block)
- if sample_rate < 1
- block.call if rand <= sample_rate
- else
- block.call
- end
- end
-
- def send_data(stat, delta, type, sample_rate = 1)
- sampled(sample_rate) do
- data = "#{stat}:#{delta}|#{type}" # TODO: check stat is valid
- data << "|@#{sample_rate}" if sample_rate < 1
- send_to_socket(data)
- end
- end
-
- def send_to_socket(data)
- logger.debug "SimpleMetrics Client send: #{data}"
- socket.send(data, 0, @host, @port)
- rescue Exception => e
- puts e.backtrace
- logger.error "SimpleMetrics Client error: #{e}"
- end
-
- def socket
- @socket ||= UDPSocket.new
- end
-
- def logger
- @logger ||= SimpleMetrics.logger
- end
-
- end
-
-end

0 comments on commit a20207c

Please sign in to comment.