microphite 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +9 -9
- data/CHANGELOG.md +4 -0
- data/lib/microphite/client/base.rb +58 -51
- data/lib/microphite/version.rb +1 -1
- metadata +20 -28
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDhjMTg3MTFjM2I1MGQzMjRmYmVmOTgzYzkwZmUxMjkxMDI3ZThkMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
MGE0MzFhNGE0MjMzMTQ1YThlNDVmYjM0M2NmNDg1ZjQwMzI3YWRlOQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWY4YzcyNDQ0MjZhOGMwYTlhYTY1NmY2YTFjMDRhOTE2OWQ2ZTE2ZDRlYWNj
|
10
|
+
YTNmY2Q1NzkwODgzMWIwMDhlMTQ3NGI2NWU5ZmM2YjAwNTM5MmI4NmViZTZm
|
11
|
+
OGIxMmQwZjFmOGE3NmY5NzRlNGExZGVlOTU1YmQyZDc1MjkzZjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGIwM2M3YTNmMTAwOGViYTg3ZDk1NmJmMmUxMGUwNjljOTc2MWU4MDBjNjg3
|
14
|
+
MDI3NWYxNzg5NjFmMDAxODUyMzZhOWUxOWY3OWUzOTQwMjMzOTlmNDdkYzll
|
15
|
+
NWQ0YzdmMTU4Mzg0MDViNzRkNGY0OGFmNjAzZGQ0MzEwYjMwNmU=
|
data/CHANGELOG.md
CHANGED
@@ -45,23 +45,11 @@ module Microphite
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def write(metrics, &block)
|
48
|
-
|
49
|
-
result = block.call
|
50
|
-
push(@write_queue, metrics) if metrics.is_a? Hash
|
51
|
-
result
|
52
|
-
else
|
53
|
-
push(@write_queue, metrics) if metrics.is_a? Hash
|
54
|
-
end
|
48
|
+
push_around(@write_queue, metrics, &block)
|
55
49
|
end
|
56
50
|
|
57
51
|
def gather(metrics, &block)
|
58
|
-
|
59
|
-
result = block.call
|
60
|
-
push(@gather_queue, metrics) if metrics.is_a? Hash
|
61
|
-
result
|
62
|
-
else
|
63
|
-
push(@gather_queue, metrics) if metrics.is_a? Hash
|
64
|
-
end
|
52
|
+
push_around(@gather_queue, metrics, &block)
|
65
53
|
end
|
66
54
|
|
67
55
|
def prefix(prefix, &block)
|
@@ -136,48 +124,38 @@ module Microphite
|
|
136
124
|
def worker_loop
|
137
125
|
loop do
|
138
126
|
wrap_errors do
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
wait_time = @next_flush - now
|
144
|
-
if wait_time > 0
|
145
|
-
@worker_event.wait(@lock, wait_time)
|
146
|
-
end
|
147
|
-
|
148
|
-
when :ending, :shutdown
|
149
|
-
flush_accumulating
|
150
|
-
wrap_errors do
|
151
|
-
shutdown
|
152
|
-
end
|
153
|
-
@status = :shutdown
|
154
|
-
@shutdown_event.broadcast
|
155
|
-
Thread.exit
|
156
|
-
|
157
|
-
else
|
158
|
-
error(AssertionError.new("Invalid status: #{@status}"))
|
159
|
-
Thread.exit
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
unwind(@write_queue).each { |m| write_metric m }
|
165
|
-
unwind(@gather_queue).each { |m| accumulate m }
|
127
|
+
event_wait
|
128
|
+
# Unwind and flush gather queue first, since the timestamps are
|
129
|
+
# created at flush. This is more sensitive to delays and fudging
|
130
|
+
unwind(@gather_queue).each { |metric| accumulate metric }
|
166
131
|
flush_accumulating if should_flush?
|
132
|
+
|
133
|
+
# Handle write queue last, since the timestamps are stored at the
|
134
|
+
# time write() is called
|
135
|
+
unwind(@write_queue).each { |metric| write_metric metric }
|
167
136
|
end
|
168
137
|
end
|
169
138
|
end
|
170
139
|
|
140
|
+
def push_around(queue, metrics, &block)
|
141
|
+
if block_given?
|
142
|
+
result = block.call
|
143
|
+
else
|
144
|
+
result = nil
|
145
|
+
end
|
146
|
+
push(queue, metrics)
|
147
|
+
result
|
148
|
+
end
|
149
|
+
|
171
150
|
def push(queue, metrics)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
queue.
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
false
|
151
|
+
if metrics.is_a? Hash
|
152
|
+
timestamp = now
|
153
|
+
cloned = metrics.clone
|
154
|
+
@lock.synchronize do
|
155
|
+
if queue.length <= @limit and @status == :running
|
156
|
+
queue.push [timestamp, cloned]
|
157
|
+
@worker_event.signal
|
158
|
+
end
|
181
159
|
end
|
182
160
|
end
|
183
161
|
end
|
@@ -203,7 +181,9 @@ module Microphite
|
|
203
181
|
end
|
204
182
|
|
205
183
|
def flush_accumulating
|
206
|
-
|
184
|
+
# Capture timestamp first. If write_metric fails, it might delay before retry
|
185
|
+
timestamp = now
|
186
|
+
@accumulating.each_pair { |k, v| write_metric(Metric.new(k, v, timestamp)) }
|
207
187
|
@accumulating.clear
|
208
188
|
@next_flush = now + @flush_interval
|
209
189
|
end
|
@@ -211,6 +191,33 @@ module Microphite
|
|
211
191
|
def should_flush?
|
212
192
|
now > @next_flush
|
213
193
|
end
|
194
|
+
|
195
|
+
def event_wait
|
196
|
+
@lock.synchronize do
|
197
|
+
if @write_queue.empty? and @gather_queue.empty?
|
198
|
+
case @status
|
199
|
+
when :running
|
200
|
+
wait_time = @next_flush - now
|
201
|
+
if wait_time > 0
|
202
|
+
@worker_event.wait(@lock, wait_time)
|
203
|
+
end
|
204
|
+
|
205
|
+
when :ending, :shutdown
|
206
|
+
flush_accumulating
|
207
|
+
wrap_errors do
|
208
|
+
shutdown
|
209
|
+
end
|
210
|
+
@status = :shutdown
|
211
|
+
@shutdown_event.broadcast
|
212
|
+
Thread.exit
|
213
|
+
|
214
|
+
else
|
215
|
+
error(AssertionError.new("Invalid status: #{@status}"))
|
216
|
+
Thread.exit
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
214
221
|
end
|
215
222
|
end
|
216
223
|
end
|
data/lib/microphite/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BZ
|
@@ -11,56 +11,50 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-11-
|
14
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
24
26
|
requirements:
|
25
27
|
- - ! '>='
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
MA==
|
29
|
-
name: rake
|
30
|
-
type: :development
|
31
|
-
prerelease: false
|
29
|
+
version: '0'
|
32
30
|
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
33
32
|
requirement: !ruby/object:Gem::Requirement
|
34
33
|
requirements:
|
35
34
|
- - ! '>='
|
36
35
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
|
36
|
+
version: '0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
MA==
|
45
|
-
name: rspec
|
46
|
-
type: :development
|
47
|
-
prerelease: false
|
43
|
+
version: '0'
|
48
44
|
- !ruby/object:Gem::Dependency
|
45
|
+
name: coveralls
|
49
46
|
requirement: !ruby/object:Gem::Requirement
|
50
47
|
requirements:
|
51
48
|
- - ! '>='
|
52
49
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
55
53
|
version_requirements: !ruby/object:Gem::Requirement
|
56
54
|
requirements:
|
57
55
|
- - ! '>='
|
58
56
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
60
|
-
MA==
|
61
|
-
name: coveralls
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
57
|
+
version: '0'
|
64
58
|
description: A tiny and fast, asynchronous graphite client
|
65
59
|
email:
|
66
60
|
- support@bz-technology.com
|
@@ -104,17 +98,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
98
|
requirements:
|
105
99
|
- - ! '>='
|
106
100
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
108
|
-
MA==
|
101
|
+
version: '0'
|
109
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
103
|
requirements:
|
111
104
|
- - ! '>='
|
112
105
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
114
|
-
MA==
|
106
|
+
version: '0'
|
115
107
|
requirements: []
|
116
108
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.1.11
|
118
110
|
signing_key:
|
119
111
|
specification_version: 4
|
120
112
|
summary: A tiny and fast, asynchronous graphite client
|