statsd.scala 0.0.1.SNAPSHOT

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/statsd.rb +38 -0
  2. data/statsd.scala.gemspec +17 -0
  3. metadata +84 -0
data/lib/statsd.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "socket"
2
+ require "rufus-json"
3
+
4
+ class Statsd
5
+ def initialize(host = "localhost", port = 8125)
6
+ @host = host
7
+ @port = port
8
+ @socket = UDPSocket.new
9
+ end
10
+
11
+ def time(stat)
12
+ start = Time.now
13
+ result = yield
14
+ timing(stat, ((Time.now - start) * 1000).round)
15
+ result
16
+ end
17
+
18
+ def inc(stat, delta = 1)
19
+ announce :action => "inc", :delta => delta, :name => stat
20
+ end
21
+
22
+ def dec(stat, delta = 1)
23
+ announce :action => "dec", :delta => delta, :name => stat
24
+ end
25
+
26
+ def mark(stat, count = 1)
27
+ announce :action => "mark", :count => count, :name => stat
28
+ end
29
+
30
+ private
31
+ def timing(name, duration)
32
+ announce :action => "timing", :duration => duration, :name => name
33
+ end
34
+
35
+ def announce(hash)
36
+ @socket.send(Rufus::Json.encode(hash), 0, @host, @port)
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "statsd.scala"
3
+ s.version = "0.0.1.SNAPSHOT"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["James Golick"]
7
+ s.date = "2010-08-31"
8
+ s.description = ""
9
+ s.email = "jamesgolick@gmail.com"
10
+ s.files = Dir["lib/**/*.rb"] + ["statsd.scala.gemspec"]
11
+ s.homepage = ""
12
+ s.rdoc_options = ["--charset=UTF-8"]
13
+ s.require_paths = ["lib"]
14
+ s.rubygems_version = "1.3.7"
15
+ s.summary = ""
16
+ s.add_dependency("rufus-json", "0.2.5")
17
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsd.scala
3
+ version: !ruby/object:Gem::Version
4
+ hash: 907030954
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - SNAPSHOT
11
+ version: 0.0.1.SNAPSHOT
12
+ platform: ruby
13
+ authors:
14
+ - James Golick
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-08-31 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rufus-json
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - "="
29
+ - !ruby/object:Gem::Version
30
+ hash: 29
31
+ segments:
32
+ - 0
33
+ - 2
34
+ - 5
35
+ version: 0.2.5
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: ""
39
+ email: jamesgolick@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/statsd.rb
48
+ - statsd.scala.gemspec
49
+ has_rdoc: true
50
+ homepage: ""
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.6.2
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: ""
83
+ test_files: []
84
+