meter 0.0.5 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/meter/backend.rb +6 -1
- data/lib/meter/configuration.rb +20 -2
- data/lib/meter/version.rb +1 -1
- data/lib/meter.rb +9 -3
- metadata +24 -39
- data/LICENSE +0 -21
- data/README.md +0 -29
- data/spec/lib/meter/backend_spec.rb +0 -18
- data/spec/lib/meter/configuration_spec.rb +0 -60
- data/spec/lib/meter_spec.rb +0 -37
- data/spec/spec_helper.rb +0 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42a8f51ce6d77b2e7570c8765c5a448875108f91
|
4
|
+
data.tar.gz: 71cfef42ff4066b498ea05ee247ce3b6c2c9051c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06db06efc2f6e02b240d55365023ab20f2bf451ce6349139ef25848b0c68d58df80d8289a5f3dd58c4ded95f3f0e543faf3a0bda37f792eaa26a194d0366914f
|
7
|
+
data.tar.gz: 64f4ee7774b78ddecf7d16df10f03c9ef9d9846bec96584a65dc12b90049f40b00b1e659563c1b240f56ff33fc26b3c0448fdc5e5b60f51b105919d60da7074e
|
data/lib/meter/backend.rb
CHANGED
@@ -166,6 +166,11 @@ module Meter
|
|
166
166
|
send_stats stat, value, :s, opts
|
167
167
|
end
|
168
168
|
|
169
|
+
def log(stat, data = {})
|
170
|
+
data = data.merge(app: @namespace, name: stat)
|
171
|
+
send_to_socket data.to_json
|
172
|
+
end
|
173
|
+
|
169
174
|
private
|
170
175
|
|
171
176
|
def send_stats(stat, delta, type, opts={})
|
@@ -183,7 +188,7 @@ module Meter
|
|
183
188
|
self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
|
184
189
|
@socket.send(message, 0, @host, @port)
|
185
190
|
rescue => boom
|
186
|
-
self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
|
191
|
+
self.class.logger.error { "boom Statsd: #{boom.class} #{boom}" } if self.class.logger
|
187
192
|
nil
|
188
193
|
end
|
189
194
|
end
|
data/lib/meter/configuration.rb
CHANGED
@@ -5,7 +5,7 @@ module Meter
|
|
5
5
|
class Configuration
|
6
6
|
|
7
7
|
attr_accessor :logger, :tags
|
8
|
-
attr_reader :primary_backend, :secondary_backend, :counter_backend
|
8
|
+
attr_reader :primary_backend, :secondary_backend, :counter_backend, :meter_backend
|
9
9
|
|
10
10
|
def initialize(options={})
|
11
11
|
@logger = options[:logger] || default_logger
|
@@ -23,6 +23,11 @@ module Meter
|
|
23
23
|
@counter_backend.port = options[:counter_port] || default_counter_port
|
24
24
|
@counter_backend.namespace = options[:namespace] || default_namespace
|
25
25
|
|
26
|
+
@meter_backend = Backend.new
|
27
|
+
@meter_backend.host = options[:meter_host] || default_host
|
28
|
+
@meter_backend.port = options[:meter_port] || default_meter_port
|
29
|
+
@meter_backend.namespace = options[:namespace] || default_namespace
|
30
|
+
|
26
31
|
@tags = options[:tags] || {}
|
27
32
|
end
|
28
33
|
|
@@ -30,6 +35,7 @@ module Meter
|
|
30
35
|
primary_backend.namespace = new_namespace
|
31
36
|
secondary_backend.namespace = new_namespace
|
32
37
|
counter_backend.namespace = new_namespace
|
38
|
+
meter_backend.namespace = new_namespace
|
33
39
|
end
|
34
40
|
|
35
41
|
def namespace
|
@@ -52,6 +58,14 @@ module Meter
|
|
52
58
|
secondary_backend.port
|
53
59
|
end
|
54
60
|
|
61
|
+
def secondary_host
|
62
|
+
secondary_backend.host
|
63
|
+
end
|
64
|
+
|
65
|
+
def secondary_port
|
66
|
+
secondary_backend.port
|
67
|
+
end
|
68
|
+
|
55
69
|
def primary_host=(new_host)
|
56
70
|
primary_backend.host = new_host
|
57
71
|
end
|
@@ -87,13 +101,17 @@ module Meter
|
|
87
101
|
end
|
88
102
|
|
89
103
|
def default_secondary_port
|
90
|
-
|
104
|
+
8127
|
91
105
|
end
|
92
106
|
|
93
107
|
def default_counter_port
|
94
108
|
3333
|
95
109
|
end
|
96
110
|
|
111
|
+
def default_meter_port
|
112
|
+
8128
|
113
|
+
end
|
114
|
+
|
97
115
|
def default_namespace
|
98
116
|
nil
|
99
117
|
end
|
data/lib/meter/version.rb
CHANGED
data/lib/meter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'meter/configuration'
|
2
3
|
|
3
4
|
# A generic wrapper for Statsd-like gauges and counters.
|
@@ -8,7 +9,6 @@ module Meter
|
|
8
9
|
def increment(key, options = {})
|
9
10
|
id = options.delete(:id)
|
10
11
|
primary.increment key, options
|
11
|
-
secondary.increment key, options
|
12
12
|
if id
|
13
13
|
counter.increment "#{key}.#{id}", options
|
14
14
|
end
|
@@ -17,7 +17,6 @@ module Meter
|
|
17
17
|
def count(key, delta, options = {})
|
18
18
|
id = options.delete(:id)
|
19
19
|
primary.count key, delta, options
|
20
|
-
secondary.count key, delta, options
|
21
20
|
if id
|
22
21
|
counter.count "#{key}.#{id}", delta, options
|
23
22
|
end
|
@@ -25,13 +24,16 @@ module Meter
|
|
25
24
|
|
26
25
|
def gauge(key, value, options = {})
|
27
26
|
primary.gauge key, value, options
|
28
|
-
secondary.gauge key, value, options
|
29
27
|
end
|
30
28
|
|
31
29
|
def histogram(key, value, options = {})
|
32
30
|
primary.histogram key, value, options
|
33
31
|
end
|
34
32
|
|
33
|
+
def log(key, data)
|
34
|
+
meter.log(key, data)
|
35
|
+
end
|
36
|
+
|
35
37
|
private
|
36
38
|
|
37
39
|
def primary
|
@@ -46,4 +48,8 @@ module Meter
|
|
46
48
|
config.counter_backend
|
47
49
|
end
|
48
50
|
|
51
|
+
def meter
|
52
|
+
config.meter_backend
|
53
|
+
end
|
54
|
+
|
49
55
|
end
|
metadata
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.5
|
4
|
+
version: 0.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- bukowskis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
none: false
|
21
|
-
name: rspec
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: '0'
|
29
|
-
none: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
28
|
+
name: guard-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
32
30
|
requirements:
|
33
|
-
- -
|
31
|
+
- - ">="
|
34
32
|
- !ruby/object:Gem::Version
|
35
33
|
version: '0'
|
36
|
-
none: false
|
37
|
-
name: guard-rspec
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- -
|
38
|
+
- - ">="
|
43
39
|
- !ruby/object:Gem::Version
|
44
40
|
version: '0'
|
45
|
-
none: false
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
42
|
+
name: rb-fsevent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
48
44
|
requirements:
|
49
|
-
- -
|
45
|
+
- - ">="
|
50
46
|
- !ruby/object:Gem::Version
|
51
47
|
version: '0'
|
52
|
-
none: false
|
53
|
-
name: rb-fsevent
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
|
-
- -
|
52
|
+
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '0'
|
61
|
-
none: false
|
62
55
|
description: A generic abstraction layer for fire and forgetting measurements via
|
63
56
|
UDP.
|
64
57
|
email:
|
@@ -66,42 +59,34 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
62
|
+
- lib/meter.rb
|
69
63
|
- lib/meter/backend.rb
|
70
64
|
- lib/meter/configuration.rb
|
71
65
|
- lib/meter/version.rb
|
72
|
-
- lib/meter.rb
|
73
|
-
- spec/lib/meter/backend_spec.rb
|
74
|
-
- spec/lib/meter/configuration_spec.rb
|
75
|
-
- spec/lib/meter_spec.rb
|
76
|
-
- spec/spec_helper.rb
|
77
|
-
- README.md
|
78
|
-
- LICENSE
|
79
66
|
homepage: https://github.com/bukowskis/meter
|
80
67
|
licenses:
|
81
68
|
- MIT
|
69
|
+
metadata: {}
|
82
70
|
post_install_message:
|
83
71
|
rdoc_options:
|
84
|
-
- --encoding
|
72
|
+
- "--encoding"
|
85
73
|
- UTF-8
|
86
74
|
require_paths:
|
87
75
|
- lib
|
88
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
77
|
requirements:
|
90
|
-
- -
|
78
|
+
- - ">="
|
91
79
|
- !ruby/object:Gem::Version
|
92
80
|
version: '0'
|
93
|
-
none: false
|
94
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
82
|
requirements:
|
96
|
-
- -
|
83
|
+
- - ">="
|
97
84
|
- !ruby/object:Gem::Version
|
98
85
|
version: '0'
|
99
|
-
none: false
|
100
86
|
requirements: []
|
101
87
|
rubyforge_project:
|
102
|
-
rubygems_version:
|
88
|
+
rubygems_version: 2.2.2
|
103
89
|
signing_key:
|
104
|
-
specification_version:
|
90
|
+
specification_version: 4
|
105
91
|
summary: A generic abstraction layer for fire and forgetting measurements via UDP.
|
106
92
|
test_files: []
|
107
|
-
has_rdoc:
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2013 Bukowskis
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Meter
|
2
|
-
|
3
|
-
BETA!
|
4
|
-
|
5
|
-
A generic abstraction layer for fire and forgetting measurements via UDP.
|
6
|
-
|
7
|
-
# Installation
|
8
|
-
|
9
|
-
```bash
|
10
|
-
gem install meter
|
11
|
-
````
|
12
|
-
|
13
|
-
# Usage
|
14
|
-
|
15
|
-
#### Syntax
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
Meter.increment key, delta, options
|
19
|
-
````
|
20
|
-
|
21
|
-
#### Examples
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
Meter.increment 'my.key'
|
25
|
-
Meter.increment 'my.key', 5
|
26
|
-
Meter.increment 'my.key', 5, sample_rate: 0.25
|
27
|
-
|
28
|
-
Meter.gauge 'my.gauge.key', 20
|
29
|
-
```
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'meter'
|
3
|
-
|
4
|
-
describe Meter::Backend do
|
5
|
-
|
6
|
-
let(:backend) { Meter.config.primary_backend }
|
7
|
-
|
8
|
-
before do
|
9
|
-
Meter.reset!
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.increment' do
|
13
|
-
it 'works and I did not make any mistakes when copy and pasting the backend from StatsD' do
|
14
|
-
backend.increment 'my.counter'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'meter/configuration'
|
3
|
-
|
4
|
-
describe Meter::Configuration do
|
5
|
-
|
6
|
-
let(:logger) { mock(:logger) }
|
7
|
-
let(:config) { Meter.config }
|
8
|
-
|
9
|
-
before do
|
10
|
-
Meter.reset!
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '.config' do
|
14
|
-
|
15
|
-
describe '#logger' do
|
16
|
-
it 'is an STDOUT logger' do
|
17
|
-
Logger.should_receive(:new).with(STDOUT).and_return logger
|
18
|
-
config.logger.should be logger
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with Rails' do
|
22
|
-
before do
|
23
|
-
ensure_module :Rails
|
24
|
-
Rails.stub!(:logger).and_return(logger)
|
25
|
-
end
|
26
|
-
|
27
|
-
after do
|
28
|
-
Object.send(:remove_const, :Rails)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'is the Rails logger' do
|
32
|
-
config.logger.should be Rails.logger
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#primary_backend and #secondary_backend' do
|
38
|
-
it 'is a Backend' do
|
39
|
-
config.primary_backend.should be_instance_of Meter::Backend
|
40
|
-
config.secondary_backend.should be_instance_of Meter::Backend
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'has the default host' do
|
44
|
-
config.primary_backend.host.should == '127.0.0.1'
|
45
|
-
config.secondary_backend.host.should == '127.0.0.1'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has the default namespace' do
|
49
|
-
config.primary_backend.namespace.should == nil
|
50
|
-
config.secondary_backend.namespace.should == nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'has the default port' do
|
54
|
-
config.primary_backend.port.should == 8125
|
55
|
-
config.secondary_backend.port.should == 8126
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
data/spec/lib/meter_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Meter do
|
4
|
-
|
5
|
-
let(:meter) { Meter }
|
6
|
-
let(:primary) { Meter.config.primary_backend }
|
7
|
-
let(:secondary) { Meter.config.secondary_backend }
|
8
|
-
let(:counter) { Meter.config.counter_backend }
|
9
|
-
|
10
|
-
describe '.increment' do
|
11
|
-
context "when given an id as option" do
|
12
|
-
it "proxies to the counter with the id" do
|
13
|
-
counter.should_receive(:increment).with("my.key.123", {})
|
14
|
-
meter.increment 'my.key', :id => 123
|
15
|
-
end
|
16
|
-
|
17
|
-
it "proxies to the primary and secondary without the id" do
|
18
|
-
primary.should_receive(:increment).with("my.key", {})
|
19
|
-
secondary.should_receive(:increment).with("my.key", {})
|
20
|
-
meter.increment 'my.key', :id => 123
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when id is NOT given as an option" do
|
25
|
-
it "doesn't proxy to the counter at all" do
|
26
|
-
counter.should_not_receive(:increment)
|
27
|
-
meter.increment 'my.key'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "proxies to the primary and secondary" do
|
31
|
-
primary.should_receive(:increment).with("my.key", {})
|
32
|
-
secondary.should_receive(:increment).with("my.key", {})
|
33
|
-
meter.increment 'my.key'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'meter'
|
2
|
-
|
3
|
-
def ensure_class_or_module(full_name, class_or_module)
|
4
|
-
full_name.to_s.split(/::/).inject(Object) do |context, name|
|
5
|
-
begin
|
6
|
-
context.const_get(name)
|
7
|
-
rescue NameError
|
8
|
-
if class_or_module == :class
|
9
|
-
context.const_set(name, Class.new)
|
10
|
-
else
|
11
|
-
context.const_set(name, Module.new)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def ensure_module(name)
|
18
|
-
ensure_class_or_module(name, :module)
|
19
|
-
end
|
20
|
-
|
21
|
-
def ensure_class(name)
|
22
|
-
ensure_class_or_module(name, :class)
|
23
|
-
end
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.before do
|
27
|
-
Meter.config.logger = nil
|
28
|
-
end
|
29
|
-
|
30
|
-
config.after do
|
31
|
-
Meter.reset!
|
32
|
-
end
|
33
|
-
end
|