collective-metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Collectfile +1 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/collective +15 -0
- data/collective.gemspec +28 -0
- data/lib/collective/cli.rb +14 -0
- data/lib/collective/service/dsl.rb +17 -0
- data/lib/collective/service.rb +20 -0
- data/lib/collective/services/sidekiq.rb +39 -0
- data/lib/collective/version.rb +3 -0
- data/lib/collective-metrics.rb +1 -0
- data/lib/collective.rb +38 -0
- metadata +164 -0
data/.gitignore
ADDED
data/Collectfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'collective/services/sidekiq'
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Eric J. Holmes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Collective
|
2
|
+
|
3
|
+
It collects metrics.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'collective-metrics'
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Add a Collectfile:
|
14
|
+
|
15
|
+
```
|
16
|
+
require 'collective/services/sidekiq'
|
17
|
+
```
|
18
|
+
|
19
|
+
```
|
20
|
+
collective start
|
21
|
+
```
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/collective
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'collective'
|
5
|
+
Bundler.require if File.exists?('Gemfile')
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'collective/cli'
|
9
|
+
Collective::CLI.start
|
10
|
+
rescue Interrupt => e
|
11
|
+
puts "\nQuitting..."
|
12
|
+
exit 1
|
13
|
+
rescue SystemExit => e
|
14
|
+
exit e.status
|
15
|
+
end
|
data/collective.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'collective/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'collective-metrics'
|
8
|
+
spec.version = Collective::VERSION
|
9
|
+
spec.authors = ["Eric J. Holmes"]
|
10
|
+
spec.email = ["eric@ejholmes.net"]
|
11
|
+
spec.description = %q{Collect and output metrics}
|
12
|
+
spec.summary = %q{Collect and output metrics}
|
13
|
+
spec.homepage = "https://github.com/remind101/collective-metrics"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rufus-scheduler'
|
22
|
+
spec.add_dependency 'thor'
|
23
|
+
spec.add_dependency 'formatted-metrics'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Collective
|
2
|
+
class Service
|
3
|
+
autoload :DSL, 'collective/service/dsl'
|
4
|
+
extend DSL
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def collect
|
13
|
+
_instrument
|
14
|
+
end
|
15
|
+
|
16
|
+
def instrument(*args, &block)
|
17
|
+
Metrics.instrument(*args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'collective'
|
data/lib/collective.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rufus-scheduler'
|
2
|
+
require 'formatted-metrics'
|
3
|
+
|
4
|
+
require 'collective/version'
|
5
|
+
|
6
|
+
module Collective
|
7
|
+
autoload :Service, 'collective/service'
|
8
|
+
|
9
|
+
module Services
|
10
|
+
autoload :Sidekiq, 'collective/services/sidekiq'
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def services
|
15
|
+
@services ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def register(service)
|
19
|
+
services << service
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
Metrics.subscribe
|
24
|
+
|
25
|
+
services.map(&:new).each do |service|
|
26
|
+
scheduler.every '1s' do
|
27
|
+
service.collect
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
scheduler.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def scheduler
|
35
|
+
@scheduler ||= Rufus::Scheduler.new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collective-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric J. Holmes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rufus-scheduler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: formatted-metrics
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Collect and output metrics
|
111
|
+
email:
|
112
|
+
- eric@ejholmes.net
|
113
|
+
executables:
|
114
|
+
- collective
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Collectfile
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/collective
|
125
|
+
- collective.gemspec
|
126
|
+
- lib/collective-metrics.rb
|
127
|
+
- lib/collective.rb
|
128
|
+
- lib/collective/cli.rb
|
129
|
+
- lib/collective/service.rb
|
130
|
+
- lib/collective/service/dsl.rb
|
131
|
+
- lib/collective/services/sidekiq.rb
|
132
|
+
- lib/collective/version.rb
|
133
|
+
homepage: https://github.com/remind101/collective-metrics
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
hash: -2076066127101853191
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
hash: -2076066127101853191
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 1.8.23
|
161
|
+
signing_key:
|
162
|
+
specification_version: 3
|
163
|
+
summary: Collect and output metrics
|
164
|
+
test_files: []
|