graphiterb 0.2.9 → 0.2.10

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.2.10
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{graphiterb}
8
- s.version = "0.2.9"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philip (flip) Kromer (@mrflip)"]
12
- s.date = %q{2010-09-20}
12
+ s.date = %q{2010-09-21}
13
13
  s.description = %q{Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com}
14
14
  s.email = %q{info@infochimps.org}
15
15
  s.extra_rdoc_files = [
@@ -12,6 +12,10 @@ module Graphiterb
12
12
  # accumulations are stored (defaults to 'graphiterb')
13
13
  attr_accessor :namespace
14
14
 
15
+ # The key used to store the last report time. Will live inside
16
+ # the namespace.
17
+ attr_accessor :report_timestamp_key
18
+
15
19
  # The Redis namespace used for the accumulators.
16
20
  attr_accessor :accumulators
17
21
 
@@ -44,18 +48,38 @@ module Graphiterb
44
48
  @namespace = options[:namespace] || 'graphiterb'
45
49
  @accumulators = Redis::Namespace.new(namespace, :redis => @redis)
46
50
  @regexp = options[:regexp] || /.*/
51
+ @report_timestamp_key = options[:report_timestamp_key] || '_last_report_timestamp_'
47
52
  super('fake_scope', options) # FIXME shouldn't have to use a fake scope
48
53
  end
49
54
 
50
55
  # Uses Redis' +getset+ call to retrieve total accumulated counts
51
56
  # from Redis and reset them to 0 atomically.
52
57
  def get_metrics metrics, since
58
+ # compute the length of the interval between the last time
59
+ # this monitor ran and now
60
+ last_report_timestamp = accumulators.get(report_timestamp_key).to_i
61
+ now = Time.now.to_i
62
+ interval = now - last_report_timestamp
63
+
53
64
  accumulators.keys.each do |target|
54
- next unless regexp =~ target
55
- current_count = accumulators.getset(target, 0) rescue 0.0
56
- rate = current_count.to_f / since.to_f rescue 0.0
65
+ next unless regexp && regexp =~ target
66
+ current_count = accumulators.getset(target, 0) rescue 0.0
67
+
68
+ # if we don't know when the last time we ran was, we bail,
69
+ # resetting the accumulated count to 0 in preparation for
70
+ # the next iteration
71
+ #
72
+ # we lost a data point this way (say the monitor went down
73
+ # for a while and we brought it back up) but we also don't
74
+ # ruin the scale of the graph...
75
+ next if last_report_timestamp == 0
76
+
77
+ rate = current_count.to_f / interval.to_f rescue 0.0
57
78
  metrics << [target, rate] # no need to scope as targets are pre-scoped
58
79
  end
80
+
81
+ # store the timestamp for this run for the next
82
+ accumulators.set(report_timestamp_key, now)
59
83
  end
60
84
 
61
85
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiterb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 9
10
- version: 0.2.9
9
+ - 10
10
+ version: 0.2.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philip (flip) Kromer (@mrflip)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 -05:00
18
+ date: 2010-09-21 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency