alephant-logger-statsd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3533696698a6e0e6f4c39212997d85cead186ad6
4
+ data.tar.gz: 79c8f158fadb773f0dc6814ad3ee647d92c9cc92
5
+ SHA512:
6
+ metadata.gz: e6cbf7e1659eb5edb9bf2adb11fc0bd34e6b868c57c4d3d6df89a902719df6d8cec6d6d15c6668e8b6857eb258062756815a2d0792e7c1e79b2e697319876fa5
7
+ data.tar.gz: b5ce96604eadbd714be006b06611a1850ed8a4742093a7a8e28082d797ec0c97733bd0bf310f464b922fdd70a22a37e8936dcaccf3bdcf145d81fb052b703871
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1 @@
1
+ jruby-1.7
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby
4
+ - 1.7.17
5
+ script: "bundle exec rake all"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Charlie Revett
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Alephant::Logger::Statsd
2
+
3
+ Statsd driver for the [alephant-logger](https://github.com/BBC-News/alephant-logger) gem, which consumes the [statsd-ruby](https://github.com/reinh/statsd) gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'alephant-logger-statsd'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alephant-logger-statsd
20
+
21
+ ## Usage
22
+
23
+ Create an instance of the driver:
24
+
25
+ ```ruby
26
+ require "alephant/logger"
27
+ require "alephant/logger/statsd"
28
+
29
+ config = {
30
+ :host => "statsd.test.service.bbc.co.uk",
31
+ :port => 6452,
32
+ :namespace => "test"
33
+ }
34
+
35
+ driver = Alephant::Logger::Statsd.new config
36
+ logger = Alephant::Logger.create([driver])
37
+ logger.increment "foo.bar"
38
+ ```
39
+
40
+ **Note** that a config is *optional*, if you leave any of the keys out then they will be replaced by the following:
41
+
42
+ ```ruby
43
+ {
44
+ :host => "localhost",
45
+ :port => 8125,
46
+ :namespace => "statsd"
47
+ }
48
+ ```
49
+
50
+ Then increment a custom metric, with a given key:
51
+
52
+ ```key
53
+ driver.increment 'front_page.response_time'
54
+ ```
55
+
56
+ You can also increment the metric by a specific interval:
57
+
58
+ ```key
59
+ driver.increment('facebook.signups', 43)
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ 1. [Fork it!](https://github.com/bbc-news/alephant-logger-statsd/fork)
65
+ 2. Create your feature branch: `git checkout -b my-new-feature`
66
+ 3. Commit your changes: `git commit -am 'Add some feature'`
67
+ 4. Push to the branch: `git push origin my-new-feature`
68
+ 5. Create a new [Pull Request](https://github.com/BBC-News/alephant-logger-statsd/compare).
69
+
70
+ ## Help
71
+
72
+ Please raise a new [issue](https://github.com/BBC-News/alephant-logger-statsd/issues/new) with the relevant label, or ping [@revett](http://github.com/revett).
@@ -0,0 +1,7 @@
1
+ $: << File.join(File.dirname(__FILE__), "lib")
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/rspec"
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alephant/logger/statsd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alephant-logger-statsd"
8
+ spec.version = Alephant::Logger::Statsd::VERSION
9
+ spec.authors = ["Charlie Revett"]
10
+ spec.email = ["charlierevett@gmail.com"]
11
+ spec.summary = %q{StatsD driver for Alephant Logger gem.}
12
+ spec.homepage = "https://github.com/BBC-News/alephant-logger-statsd"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "statsd-ruby"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec-nc"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rspec", "~> 3.1"
27
+ spec.add_development_dependency "rake-rspec"
28
+ end
@@ -0,0 +1,38 @@
1
+ require "statsd-ruby"
2
+ require "thread"
3
+
4
+ module Alephant
5
+ module Logger
6
+ class Statsd
7
+ def initialize(config = {})
8
+ @server = connect defaults.merge(config)
9
+ end
10
+
11
+ def increment(key, interval = 1)
12
+ send_data { server.increment(key, interval) }
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :server
18
+
19
+ def connect(config)
20
+ ::Statsd.new(config[:host], config[:port]).tap do |s|
21
+ s.namespace = config[:namespace]
22
+ end
23
+ end
24
+
25
+ def defaults
26
+ {
27
+ :host => "localhost",
28
+ :port => 8125,
29
+ :namespace => "statsd"
30
+ }
31
+ end
32
+
33
+ def send_data
34
+ Thread.new { yield }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module Alephant
2
+ module Logger
3
+ class Statsd
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "pry"
@@ -0,0 +1,89 @@
1
+ require "alephant/logger/statsd"
2
+
3
+ describe Alephant::Logger::Statsd do
4
+ subject { described_class }
5
+ let(:server) do
6
+ instance_double(
7
+ ::Statsd,
8
+ :increment => true,
9
+ :namespace= => true
10
+ )
11
+ end
12
+
13
+ before do
14
+ allow(::Statsd).to receive(:new) { server }
15
+ end
16
+
17
+ describe ".new" do
18
+ context "default config" do
19
+ let(:config) do
20
+ {
21
+ :host => "localhost",
22
+ :port => 8125,
23
+ :namespace => "statsd"
24
+ }
25
+ end
26
+
27
+ specify do
28
+ subject.new
29
+ expect(::Statsd).to have_received(:new).once.with(
30
+ config[:host],
31
+ config[:port]
32
+ )
33
+ end
34
+
35
+ specify do
36
+ subject.new
37
+ expect(server).to have_received(:namespace=).once.with(
38
+ config[:namespace]
39
+ )
40
+ end
41
+ end
42
+
43
+ context "custom config" do
44
+ let(:config) do
45
+ {
46
+ :host => "192.168.59.103",
47
+ :port => 1234,
48
+ :namespace => "batman"
49
+ }
50
+ end
51
+
52
+ specify do
53
+ subject.new config
54
+ expect(::Statsd).to have_received(:new).once.with(
55
+ config[:host],
56
+ config[:port]
57
+ )
58
+ end
59
+
60
+ specify do
61
+ subject.new config
62
+ expect(server).to have_received(:namespace=).once.with(
63
+ config[:namespace]
64
+ )
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#increment" do
70
+ let(:driver) { subject.new }
71
+ let(:key) { "batman" }
72
+
73
+ context "default interval" do
74
+ specify do
75
+ driver.increment(key).join
76
+ expect(server).to have_received(:increment).once.with(key, 1)
77
+ end
78
+ end
79
+
80
+ context "custom interval" do
81
+ let(:interval) { 10 }
82
+
83
+ specify do
84
+ driver.increment(key, interval).join
85
+ expect(server).to have_received(:increment).once.with(key, interval)
86
+ end
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alephant-logger-statsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charlie Revett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '>='
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: statsd-ruby
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.7'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: rspec-nc
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: pry
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
89
+ name: rspec
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ name: rake-rspec
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - charlierevett@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .ruby-version
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - alephant-logger-statsd.gemspec
126
+ - lib/alephant/logger/statsd.rb
127
+ - lib/alephant/logger/statsd/version.rb
128
+ - spec/spec_helper.rb
129
+ - spec/statsd_spec.rb
130
+ homepage: https://github.com/BBC-News/alephant-logger-statsd
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.1.9
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: StatsD driver for Alephant Logger gem.
154
+ test_files:
155
+ - spec/spec_helper.rb
156
+ - spec/statsd_spec.rb