metriks 0.9.7.2 → 0.9.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/metriks.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Metriks
3
- VERSION = '0.9.7.2'
3
+ VERSION = '0.9.7.3'
4
4
 
5
5
  def self.get(name)
6
6
  Metriks::Registry.default.get(name)
@@ -7,22 +7,20 @@ module Metriks::Reporter
7
7
  @log_level = options[:log_level] || ::Logger::INFO
8
8
  @prefix = options[:prefix] || 'metriks:'
9
9
 
10
- @registry = options[:registry] || Metriks::Registry.default
11
- @interval = options[:interval] || 60
12
- @on_error = options[:on_error] || proc { |ex| }
10
+ @registry = options[:registry] || Metriks::Registry.default
11
+ @time_tracker = TimeTracker.new(options[:interval] || 60)
12
+ @on_error = options[:on_error] || proc { |ex| }
13
13
  end
14
14
 
15
15
  def start
16
16
  @thread ||= Thread.new do
17
17
  loop do
18
- sleep @interval
19
-
20
- Thread.new do
21
- begin
22
- write
23
- rescue Exception => ex
24
- @on_error[ex] rescue nil
25
- end
18
+ @time_tracker.sleep
19
+
20
+ begin
21
+ write
22
+ rescue Exception => ex
23
+ @on_error[ex] rescue nil
26
24
  end
27
25
  end
28
26
  end
@@ -114,5 +112,25 @@ module Metriks::Reporter
114
112
  end
115
113
  end.join(' ')
116
114
  end
115
+
116
+ class TimeTracker
117
+ def initialize(interval)
118
+ @interval = interval
119
+ @next_time = Time.now.to_f
120
+ end
121
+
122
+ def sleep
123
+ sleep_time = next_time - Time.now.to_f
124
+ if sleep_time > 0
125
+ Kernel.sleep(sleep_time)
126
+ end
127
+ end
128
+
129
+ def next_time
130
+ now = Time.now.to_f
131
+ @next_time = now if @next_time <= now
132
+ @next_time += @interval - (@next_time % @interval)
133
+ end
134
+ end
117
135
  end
118
136
  end
data/metriks.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'metriks'
16
- s.version = '0.9.7.2'
17
- s.date = '2012-03-26'
16
+ s.version = '0.9.7.3'
17
+ s.date = '2012-03-27'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 9
8
8
  - 7
9
- - 2
10
- version: 0.9.7.2
9
+ - 3
10
+ version: 0.9.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Lindvall
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-26 00:00:00 -07:00
18
+ date: 2012-03-27 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency