meter 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/meter/backend.rb +23 -2
- data/lib/meter/configuration.rb +27 -0
- data/lib/meter/version.rb +1 -1
- data/lib/meter.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b51363f08ba9926173d4fc3ea17658953d17621
|
4
|
+
data.tar.gz: df0465fd8394b30a9723c8958d171a9976ea1121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bfb300157cea6663debde191fa1ad5e460329764422f6608da0f3e12de7195273fa7a7a8b9848610fc0d6fc8ac9914859caa2b3e4a63ac03415195020d27812
|
7
|
+
data.tar.gz: 94945415dfd1ad008a7d89a1ea5b53ff29316333feabccc4211d1f4292d5f2ff8bcb2d1145f51d5ad074119e5ae48318173308bed89dbe50f5b50af72d498eb5
|
data/lib/meter/backend.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'socket'
|
2
|
+
require 'pathname'
|
3
|
+
|
2
4
|
|
3
5
|
# Copy and paste from https://github.com/DataDog/dogstatsd-ruby/blob/master/lib/statsd.rb
|
4
6
|
# Changes:
|
@@ -24,6 +26,11 @@ module Meter
|
|
24
26
|
# A namespace to prepend to all statsd calls.
|
25
27
|
attr_reader :namespace
|
26
28
|
|
29
|
+
# A String describing the environment, useful to distinguish staging/production
|
30
|
+
attr_reader :environment
|
31
|
+
|
32
|
+
attr_reader :log_dir
|
33
|
+
|
27
34
|
# StatsD host. Defaults to 127.0.0.1.
|
28
35
|
attr_accessor :host
|
29
36
|
|
@@ -52,6 +59,10 @@ module Meter
|
|
52
59
|
@prefix = "#{namespace}." if @namespace
|
53
60
|
end
|
54
61
|
|
62
|
+
def environment=(new_environment)
|
63
|
+
@environment = new_environment.to_s
|
64
|
+
end
|
65
|
+
|
55
66
|
def host=(host) #:nodoc:
|
56
67
|
@host = host || '127.0.0.1'
|
57
68
|
end
|
@@ -60,6 +71,10 @@ module Meter
|
|
60
71
|
@port = port || 8125
|
61
72
|
end
|
62
73
|
|
74
|
+
def log_dir=(log_dir)
|
75
|
+
@log_dir = Pathname.new log_dir
|
76
|
+
end
|
77
|
+
|
63
78
|
# Sends an increment (count = 1) for the given stat to the statsd server.
|
64
79
|
#
|
65
80
|
# @param [String] stat stat name
|
@@ -167,8 +182,14 @@ module Meter
|
|
167
182
|
end
|
168
183
|
|
169
184
|
def log(stat, data = {})
|
170
|
-
data =
|
171
|
-
|
185
|
+
data = { environment: environment }.merge data
|
186
|
+
data.merge! app: namespace, statname: stat
|
187
|
+
File.open(log_dir.join('application.json.log'), 'a') {|f| f.puts(data.to_json) }
|
188
|
+
end
|
189
|
+
|
190
|
+
def increment_and_log(stat, data = {})
|
191
|
+
increment stat
|
192
|
+
log stat, data
|
172
193
|
end
|
173
194
|
|
174
195
|
private
|
data/lib/meter/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'pathname'
|
2
3
|
require 'meter/backend'
|
3
4
|
|
4
5
|
module Meter
|
@@ -9,24 +10,31 @@ module Meter
|
|
9
10
|
|
10
11
|
def initialize(options={})
|
11
12
|
@logger = options[:logger] || default_logger
|
13
|
+
|
12
14
|
@primary_backend = Backend.new
|
13
15
|
@primary_backend.host = options[:primary_host] || default_host
|
14
16
|
@primary_backend.port = options[:primary_port] || default_port
|
15
17
|
@primary_backend.namespace = options[:namespace] || default_namespace
|
18
|
+
@primary_backend.environment = options[:environment] || default_environment
|
19
|
+
|
16
20
|
@secondary_backend = Backend.new
|
17
21
|
@secondary_backend.host = options[:secondary_host] || ENV['METER_SECONDARY_HOST'] || default_host
|
18
22
|
@secondary_backend.port = options[:secondary_port] || default_secondary_port
|
19
23
|
@secondary_backend.namespace = options[:namespace] || default_namespace
|
24
|
+
@secondary_backend.environment = options[:environment] || default_environment
|
20
25
|
|
21
26
|
@counter_backend = Backend.new
|
22
27
|
@counter_backend.host = options[:counter_host] || default_host
|
23
28
|
@counter_backend.port = options[:counter_port] || default_counter_port
|
24
29
|
@counter_backend.namespace = options[:namespace] || default_namespace
|
30
|
+
@counter_backend.environment = options[:environment] || default_environment
|
25
31
|
|
26
32
|
@meter_backend = Backend.new
|
27
33
|
@meter_backend.host = options[:meter_host] || default_host
|
28
34
|
@meter_backend.port = options[:meter_port] || default_meter_port
|
29
35
|
@meter_backend.namespace = options[:namespace] || default_namespace
|
36
|
+
@meter_backend.environment = options[:environment] || default_environment
|
37
|
+
@meter_backend.log_dir = options[:meter_log_dir] || default_meter_log_dir
|
30
38
|
|
31
39
|
@tags = options[:tags] || {}
|
32
40
|
end
|
@@ -38,6 +46,13 @@ module Meter
|
|
38
46
|
meter_backend.namespace = new_namespace
|
39
47
|
end
|
40
48
|
|
49
|
+
def environment=(new_environment)
|
50
|
+
primary_backend.environment = new_environment
|
51
|
+
secondary_backend.environment = new_environment
|
52
|
+
counter_backend.environment = new_environment
|
53
|
+
meter_backend.environment = new_environment
|
54
|
+
end
|
55
|
+
|
41
56
|
def namespace
|
42
57
|
primary_backend.namespace
|
43
58
|
end
|
@@ -116,6 +131,18 @@ module Meter
|
|
116
131
|
nil
|
117
132
|
end
|
118
133
|
|
134
|
+
def default_environment
|
135
|
+
return Rails.env if defined?(Rails)
|
136
|
+
return ENV['RACK_ENV'] if ENV['RACK_ENV'].to_s != ''
|
137
|
+
return ENV['NODE_CHEF_ENVIRONMENT'] if ENV['NODE_CHEF_ENVIRONMENT'].to_s != ''
|
138
|
+
'unknown'
|
139
|
+
end
|
140
|
+
|
141
|
+
def default_meter_log_dir
|
142
|
+
return Rails.root.join('log') if defined?(Rails)
|
143
|
+
Pathname.pwd
|
144
|
+
end
|
145
|
+
|
119
146
|
end
|
120
147
|
end
|
121
148
|
|
data/lib/meter/version.rb
CHANGED
data/lib/meter.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bukowskis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|