graphiterb 0.2.6 → 0.2.7
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 +1 -1
- data/graphiterb.gemspec +4 -2
- data/lib/graphiterb.rb +2 -1
- data/lib/graphiterb/accumulator.rb +81 -0
- data/lib/graphiterb/monitors.rb +1 -0
- data/lib/graphiterb/monitors/accumulations_consumer.rb +51 -0
- data/lib/graphiterb/sender.rb +1 -0
- data/lib/graphiterb/utils/log.rb +1 -3
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
data/graphiterb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{graphiterb}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.7"
|
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-
|
12
|
+
s.date = %q{2010-09-10}
|
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 = [
|
@@ -32,7 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"examples/toy.rb",
|
33
33
|
"graphiterb.gemspec",
|
34
34
|
"lib/graphiterb.rb",
|
35
|
+
"lib/graphiterb/accumulator.rb",
|
35
36
|
"lib/graphiterb/monitors.rb",
|
37
|
+
"lib/graphiterb/monitors/accumulations_consumer.rb",
|
36
38
|
"lib/graphiterb/monitors/directory_tree.rb",
|
37
39
|
"lib/graphiterb/monitors/disk_space.rb",
|
38
40
|
"lib/graphiterb/monitors/system.rb",
|
data/lib/graphiterb.rb
CHANGED
@@ -3,11 +3,12 @@ require 'graphiterb/utils'
|
|
3
3
|
module Graphiterb
|
4
4
|
autoload :Monitors, 'graphiterb/monitors'
|
5
5
|
autoload :Sender, 'graphiterb/sender'
|
6
|
+
autoload :Accumulator, 'graphiterb/accumulator'
|
6
7
|
end
|
7
8
|
|
8
9
|
Settings.use :define, :config_file
|
9
10
|
|
10
|
-
Settings.define :log,
|
11
|
+
Settings.define :log, :description => "Log output for Graphiterb"
|
11
12
|
Settings.define :carbon_server, :default => 'localhost', :description => "Host address for carbon database server", :required => true
|
12
13
|
Settings.define :carbon_port, :default => '2003', :description => "Port for carbon database server", :required => true
|
13
14
|
Settings.define :update_delay, :default => 30, :description => "How long to wait between updates. Must be faster than the value in the graphite/conf/storage-schemas", :required => true, :type => Integer
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Graphiterb
|
2
|
+
|
3
|
+
# An accumulator that uses a Redis database as a fast store.
|
4
|
+
#
|
5
|
+
# a = Accumulator.new
|
6
|
+
# a.increment('my_value')
|
7
|
+
#
|
8
|
+
# It's assumed that the Redis database is local and on the default
|
9
|
+
# port, but pass in :host or :port (or any other options Redis.new
|
10
|
+
# understands) to change this.
|
11
|
+
#
|
12
|
+
# By default incrementing 'my_value' which actually increment a
|
13
|
+
# counter stored at the key
|
14
|
+
# 'graphiterb_accumulator:my_value:HOSTNAME'.
|
15
|
+
#
|
16
|
+
# See Graphiterb::Monitors::AccumulationsConsumer for the periodic
|
17
|
+
# monitor that will consume the accumulated counts.
|
18
|
+
class Accumulator
|
19
|
+
|
20
|
+
# The Redis database.
|
21
|
+
attr_accessor :redis
|
22
|
+
|
23
|
+
# The Redis namespace used for the accumulators.
|
24
|
+
attr_accessor :accumulators
|
25
|
+
|
26
|
+
# The top-level scope under which to accumulate.
|
27
|
+
attr_accessor :main_scope
|
28
|
+
|
29
|
+
# Provides methods for finding out about the node this code is
|
30
|
+
# running on.
|
31
|
+
include Graphiterb::Utils::SystemInfo
|
32
|
+
|
33
|
+
# Initialize a new Accumulator.
|
34
|
+
#
|
35
|
+
# Takes the same options as Redis.new.
|
36
|
+
#
|
37
|
+
# @param [String] main_scope
|
38
|
+
# @param [Hash] options
|
39
|
+
def initialize main_scope, options={}
|
40
|
+
require 'redis'
|
41
|
+
require 'redis-namespace'
|
42
|
+
@main_scope = main_scope
|
43
|
+
@redis = Redis.new(options)
|
44
|
+
@accumulators = Redis::Namespace.new('graphiterb_accumulators', :redis => redis)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Increment the Graphite target +args+ by the given +amount+.
|
48
|
+
#
|
49
|
+
# The target will be automatically scoped, see Accumulator#scope.
|
50
|
+
#
|
51
|
+
# @param [Integer] amount
|
52
|
+
# @param [Array<String>, String] args
|
53
|
+
def increment_by amount, *args
|
54
|
+
accumulators.incrby(scope(*args), amount)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Increment the Graphite target +args+.
|
58
|
+
#
|
59
|
+
# @param [Array<String>, String] args
|
60
|
+
def increment *args
|
61
|
+
accumulators.incr(scope(*args))
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return the scoped accumulator name.
|
65
|
+
#
|
66
|
+
# This will be a valid string target that can be passed directly
|
67
|
+
# to Graphite.
|
68
|
+
#
|
69
|
+
# a = Accumulator.new('scrapers')
|
70
|
+
# a.scope('foo.bar', 'baz')
|
71
|
+
# #=> 'scrapers.foo.bar.baz.ip-120.112.4.383'
|
72
|
+
#
|
73
|
+
# @param [Array<String>, String] args
|
74
|
+
# @return [String]
|
75
|
+
def scope *args
|
76
|
+
[main_scope, args, hostname].flatten.compact.map(&:to_s).join('.')
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/lib/graphiterb/monitors.rb
CHANGED
@@ -4,6 +4,7 @@ module Graphiterb
|
|
4
4
|
autoload :DiskSpace, 'graphiterb/monitors/disk_space'
|
5
5
|
autoload :System, 'graphiterb/monitors/system'
|
6
6
|
autoload :DirectoryTree, 'graphiterb/monitors/directory_tree'
|
7
|
+
autoload :AccumulationsConsumer, 'graphiterb/monitors/accumulations_consumer'
|
7
8
|
|
8
9
|
# Accepts a lightweight call every iteration.
|
9
10
|
#
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Graphiterb
|
2
|
+
module Monitors
|
3
|
+
|
4
|
+
# A monitor which consumes counts accumulated in a Redis store by
|
5
|
+
# Graphiterb::Accumulator.
|
6
|
+
class AccumulationsConsumer < Graphiterb::Monitors::PeriodicMonitor
|
7
|
+
|
8
|
+
# The Redis database.
|
9
|
+
attr_accessor :redis
|
10
|
+
|
11
|
+
# The Redis namespace used for the accumulators.
|
12
|
+
attr_accessor :accumulators
|
13
|
+
|
14
|
+
# A regular expression that must match the Graphite target
|
15
|
+
# (defaults to always matching).
|
16
|
+
attr_accessor :regexp
|
17
|
+
|
18
|
+
# Instantiate a new AccumulationsConsumer.
|
19
|
+
#
|
20
|
+
# Options are passed to Redis.new as well as
|
21
|
+
# Graphiterb::Monitors::PeriodicMonitor.
|
22
|
+
#
|
23
|
+
# Include the :regexp option if you want this monitor to only
|
24
|
+
# consume keys corresponding to Graphite targets which match the
|
25
|
+
# regexp. This is useful for having multiple
|
26
|
+
# AccumulationsConsumer monitors running with different
|
27
|
+
# frequencies tracking different Graphite target families.
|
28
|
+
def initialize options={}
|
29
|
+
require 'redis'
|
30
|
+
require 'redis-namespace'
|
31
|
+
@redis = Redis.new(options)
|
32
|
+
@accumulators = Redis::Namespace.new('graphiterb_accumulators', :redis => @redis)
|
33
|
+
@regexp = options[:regexp] || /.*/
|
34
|
+
super('fake_scope', options)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Uses Redis' +getset+ call to retrieve total accumulated counts
|
38
|
+
# from Redis and reset them to 0 atomically.
|
39
|
+
def get_metrics metrics, since
|
40
|
+
accumulators.keys.each do |target|
|
41
|
+
next unless regexp =~ target
|
42
|
+
current_count = accumulators.getset(target, 0) rescue 0.0
|
43
|
+
rate = current_count.to_f / since.to_f rescue 0.0
|
44
|
+
metrics << [target, rate] # no need to scope as targets are pre-scoped
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/graphiterb/sender.rb
CHANGED
data/lib/graphiterb/utils/log.rb
CHANGED
@@ -4,10 +4,8 @@ module Graphiterb
|
|
4
4
|
|
5
5
|
class << self; attr_accessor :log end
|
6
6
|
|
7
|
-
# Create a Logger and point it at Graphiterb::LOG_FILE_DESTINATION which is
|
8
|
-
# set in ~/.imwrc and defaults to STDERR.
|
9
7
|
def self.instantiate_logger!
|
10
|
-
Graphiterb.log ||= Logger.new(Settings[:log])
|
8
|
+
Graphiterb.log ||= Logger.new(Settings[:log] || STDOUT)
|
11
9
|
Graphiterb.log.datetime_format = "%Y%m%d-%H:%M:%S "
|
12
10
|
Graphiterb.log.level = Logger::INFO
|
13
11
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
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-
|
18
|
+
date: 2010-09-10 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -87,7 +87,9 @@ files:
|
|
87
87
|
- examples/toy.rb
|
88
88
|
- graphiterb.gemspec
|
89
89
|
- lib/graphiterb.rb
|
90
|
+
- lib/graphiterb/accumulator.rb
|
90
91
|
- lib/graphiterb/monitors.rb
|
92
|
+
- lib/graphiterb/monitors/accumulations_consumer.rb
|
91
93
|
- lib/graphiterb/monitors/directory_tree.rb
|
92
94
|
- lib/graphiterb/monitors/disk_space.rb
|
93
95
|
- lib/graphiterb/monitors/system.rb
|