collective-metrics 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Collectfile +2 -1
- data/collective.gemspec +7 -7
- data/lib/collective/builder.rb +30 -0
- data/lib/collective/cli.rb +0 -1
- data/lib/collective/collector/dsl.rb +18 -0
- data/lib/collective/{service.rb → collector.rb} +4 -4
- data/lib/collective/collectors/redis.rb +28 -0
- data/lib/collective/collectors/sidekiq.rb +35 -0
- data/lib/collective/version.rb +1 -1
- data/lib/collective.rb +8 -22
- metadata +21 -19
- data/lib/collective/service/dsl.rb +0 -17
- data/lib/collective/services/sidekiq.rb +0 -39
data/Collectfile
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
use Collective::Collectors::Sidekiq
|
2
|
+
use Collective::Collectors::Redis
|
data/collective.gemspec
CHANGED
@@ -6,21 +6,21 @@ require 'collective/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'collective-metrics'
|
8
8
|
spec.version = Collective::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Eric J. Holmes']
|
10
|
+
spec.email = ['eric@ejholmes.net']
|
11
11
|
spec.description = %q{Collect and output metrics}
|
12
12
|
spec.summary = %q{Collect and output metrics}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/remind101/collective-metrics'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'rufus-scheduler'
|
22
|
-
spec.add_dependency 'thor'
|
23
|
-
spec.add_dependency 'formatted-metrics'
|
21
|
+
spec.add_dependency 'rufus-scheduler', '~> 2.0'
|
22
|
+
spec.add_dependency 'thor', '~> 0.18'
|
23
|
+
spec.add_dependency 'formatted-metrics', '~> 0.1'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
26
|
spec.add_development_dependency 'rake'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Collective
|
2
|
+
class Builder
|
3
|
+
DEFAULT_RESOLUTION = '5s'.freeze
|
4
|
+
|
5
|
+
def use(klass, *args)
|
6
|
+
collectors << [klass, args]
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
collectors.each do |(klass, args)|
|
11
|
+
collector = klass.new(*args)
|
12
|
+
scheduler.every klass.resolution || DEFAULT_RESOLUTION do
|
13
|
+
collector.collect
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
scheduler.join
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def collectors
|
23
|
+
@collectors ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def scheduler
|
27
|
+
@scheduler ||= Rufus::Scheduler.new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/collective/cli.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Collective
|
2
|
+
class Collector
|
3
|
+
module DSL
|
4
|
+
def requires(libs)
|
5
|
+
Array(libs).each { |lib| require lib.to_s }
|
6
|
+
end
|
7
|
+
|
8
|
+
def collect(&block)
|
9
|
+
define_method :collect, &block
|
10
|
+
end
|
11
|
+
|
12
|
+
def resolution(resolution = nil)
|
13
|
+
@resolution = resolution if resolution
|
14
|
+
@resolution
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Collective
|
2
|
-
class
|
3
|
-
autoload :DSL, 'collective/
|
2
|
+
class Collector
|
3
|
+
autoload :DSL, 'collective/collector/dsl'
|
4
4
|
extend DSL
|
5
5
|
|
6
6
|
attr_reader :options
|
@@ -9,8 +9,8 @@ module Collective
|
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
|
-
def collect
|
13
|
-
|
12
|
+
def collect!
|
13
|
+
collect
|
14
14
|
end
|
15
15
|
|
16
16
|
def instrument(*args, &block)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Collective::Collectors
|
2
|
+
class Redis < Collective::Collector
|
3
|
+
MEGABYTE = 1024 * 1024
|
4
|
+
|
5
|
+
requires :redis
|
6
|
+
|
7
|
+
collect do
|
8
|
+
instrument 'redis.used_memory', (info['used_memory'].to_f / MEGABYTE).round(2)
|
9
|
+
instrument 'redis.connected_clients', info['connected_clients']
|
10
|
+
instrument 'redis.blocked_clients', info['blocked_clients']
|
11
|
+
instrument 'redis.connected_slaves', info['connected_slaves']
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def info
|
17
|
+
redis.info
|
18
|
+
end
|
19
|
+
|
20
|
+
def redis
|
21
|
+
@redis ||= url ? ::Redis.new(url: url) : ::Redis.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def url
|
25
|
+
options[:url]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Collective::Collectors
|
2
|
+
class Sidekiq < Collective::Collector
|
3
|
+
requires :sidekiq
|
4
|
+
|
5
|
+
collect do
|
6
|
+
instrument 'sidekiq.queues.processed', stats.processed
|
7
|
+
instrument 'sidekiq.queues.failed', stats.failed
|
8
|
+
instrument 'sidekiq.queues.enqueued', stats.enqueued
|
9
|
+
instrument 'sidekiq.workers.busy', workers
|
10
|
+
|
11
|
+
queues.each do |queue, depth|
|
12
|
+
instrument 'sidekiq.queue.enqueued', depth, source: queue
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def stats
|
19
|
+
::Sidekiq::Stats.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def queues
|
23
|
+
stats.queues
|
24
|
+
end
|
25
|
+
|
26
|
+
def workers
|
27
|
+
::Sidekiq.redis { |conn|
|
28
|
+
conn
|
29
|
+
.smembers('workers')
|
30
|
+
.map { |w| conn.get("worker:#{w}") }
|
31
|
+
.compact
|
32
|
+
}.length
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/collective/version.rb
CHANGED
data/lib/collective.rb
CHANGED
@@ -4,35 +4,21 @@ require 'formatted-metrics'
|
|
4
4
|
require 'collective/version'
|
5
5
|
|
6
6
|
module Collective
|
7
|
-
autoload :
|
7
|
+
autoload :Collector, 'collective/collector'
|
8
|
+
autoload :Builder, 'collective/builder'
|
8
9
|
|
9
|
-
module
|
10
|
-
autoload :Sidekiq, 'collective/
|
10
|
+
module Collectors
|
11
|
+
autoload :Sidekiq, 'collective/collectors/sidekiq'
|
12
|
+
autoload :Redis, 'collective/collectors/redis'
|
11
13
|
end
|
12
14
|
|
13
15
|
class << self
|
14
|
-
def services
|
15
|
-
@services ||= []
|
16
|
-
end
|
17
|
-
|
18
|
-
def register(service)
|
19
|
-
services << service
|
20
|
-
end
|
21
|
-
|
22
16
|
def run
|
23
17
|
Metrics.subscribe
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
scheduler.join
|
32
|
-
end
|
33
|
-
|
34
|
-
def scheduler
|
35
|
-
@scheduler ||= Rufus::Scheduler.new
|
19
|
+
builder = Builder.new
|
20
|
+
builder.instance_eval File.read('Collectfile')
|
21
|
+
builder.run
|
36
22
|
end
|
37
23
|
end
|
38
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collective-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,56 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rufus-scheduler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
29
|
+
version: '2.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: thor
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
37
|
+
version: '0.18'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
45
|
+
version: '0.18'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: formatted-metrics
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
53
|
+
version: '0.1'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.1'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: bundler
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,10 +125,12 @@ files:
|
|
125
125
|
- collective.gemspec
|
126
126
|
- lib/collective-metrics.rb
|
127
127
|
- lib/collective.rb
|
128
|
+
- lib/collective/builder.rb
|
128
129
|
- lib/collective/cli.rb
|
129
|
-
- lib/collective/
|
130
|
-
- lib/collective/
|
131
|
-
- lib/collective/
|
130
|
+
- lib/collective/collector.rb
|
131
|
+
- lib/collective/collector/dsl.rb
|
132
|
+
- lib/collective/collectors/redis.rb
|
133
|
+
- lib/collective/collectors/sidekiq.rb
|
132
134
|
- lib/collective/version.rb
|
133
135
|
homepage: https://github.com/remind101/collective-metrics
|
134
136
|
licenses:
|
@@ -145,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
147
|
version: '0'
|
146
148
|
segments:
|
147
149
|
- 0
|
148
|
-
hash:
|
150
|
+
hash: 386385479699394327
|
149
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
152
|
none: false
|
151
153
|
requirements:
|
@@ -154,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
156
|
version: '0'
|
155
157
|
segments:
|
156
158
|
- 0
|
157
|
-
hash:
|
159
|
+
hash: 386385479699394327
|
158
160
|
requirements: []
|
159
161
|
rubyforge_project:
|
160
162
|
rubygems_version: 1.8.23
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Collective
|
2
|
-
class Service
|
3
|
-
module DSL
|
4
|
-
def inherited(base)
|
5
|
-
Collective.register(base)
|
6
|
-
end
|
7
|
-
|
8
|
-
def requires(libs)
|
9
|
-
Array(libs).each { |lib| require lib.to_s }
|
10
|
-
end
|
11
|
-
|
12
|
-
def instrument(&block)
|
13
|
-
define_method :_instrument, &block
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Collective::Services
|
2
|
-
class Sidekiq < Collective::Service
|
3
|
-
MEGABYTE = 1024 * 1024
|
4
|
-
|
5
|
-
requires :sidekiq
|
6
|
-
|
7
|
-
instrument do
|
8
|
-
instrument 'queues.processed', stats.processed
|
9
|
-
instrument 'queues.failed', stats.failed
|
10
|
-
instrument 'queues.enqueued', stats.enqueued
|
11
|
-
instrument 'workers.busy', workers
|
12
|
-
|
13
|
-
stats.queues.each do |queue, depth|
|
14
|
-
instrument 'queue.enqueued', depth, queue
|
15
|
-
end
|
16
|
-
|
17
|
-
# General redis metrics
|
18
|
-
info = ::Sidekiq.redis { |conn| conn.info }
|
19
|
-
instrument 'redis.used_memory', ( info['used_memory'].to_f / MEGABYTE ).round(2)
|
20
|
-
instrument 'redis.connected_clients', info['connected_clients']
|
21
|
-
instrument 'redis.blocked_clients', info['blocked_clients']
|
22
|
-
instrument 'redis.connected_slaves', info['connected_slaves']
|
23
|
-
instrument 'redis.ops_per_sec', info['instantaneous_ops_per_sec']
|
24
|
-
end
|
25
|
-
|
26
|
-
def stats
|
27
|
-
::Sidekiq::Stats.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def workers
|
31
|
-
::Sidekiq.redis { |conn|
|
32
|
-
conn
|
33
|
-
.smembers('workers')
|
34
|
-
.map { |w| conn.get("worker:#{w}") }
|
35
|
-
.compact
|
36
|
-
}.length
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|