sidekiq-monitor-stats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +23 -0
- data/README.md +87 -0
- data/Rakefile +11 -0
- data/lib/sidekiq/monitor/stats.rb +35 -0
- data/lib/sidekiq/monitor/web.rb +19 -0
- data/sidekiq-monitor-stats.gemspec +26 -0
- data/test/sidekiq-monitor-stats_test.rb +53 -0
- data/test/sidekiq-monitor-web_test.rb +54 -0
- data/test/test_helper.rb +4 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00425866b37d303ebbc7a42819cc4826f1b0080e
|
4
|
+
data.tar.gz: 1a1b4d7432c44b4d34830e9675a5c611167fefdc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abd30bb60dac07941aff830d9ce0988ac7804b554e3ecd2784e178f3de7baa890eae86a3928219dbc46bdc8fe8e37223532eae649bc37524297a3fb7e4b596a7
|
7
|
+
data.tar.gz: b87592c27829b55f208fdd0651e6ba46ed368aa2bc9f3331d35625afe300ecb89b01e05ae95759600630469060d93944ebd66e39b65fa5f22b184e5f0d05ca85
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
by Albert Llop for Harvest
|
2
|
+
Copyright (c) 2015 by Harvest
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Sidekiq Monitor Stats
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/harvesthq/sidekiq-monitor-stats.svg)](https://travis-ci.org/harvesthq/sidekiq-monitor-stats)
|
4
|
+
|
5
|
+
Add an endpoint to your running application that is running Sidekiq that
|
6
|
+
returns useful data in JSON format.
|
7
|
+
|
8
|
+
The intention is to provide useful data for something like a sensu check
|
9
|
+
to monitor if Sidekiq is working correctly.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'sidekiq-monitor-stats'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install sidekiq-monitor-stats
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
This will automatically add another endpoint wherever you have mounted
|
30
|
+
your sidekiq web. Just visit `<mounted-path>/monitor-stats` to see some stats.
|
31
|
+
|
32
|
+
This is an example of the output you'll get:
|
33
|
+
|
34
|
+
```json
|
35
|
+
{
|
36
|
+
"queues":{
|
37
|
+
"default":{
|
38
|
+
"backlog":15,
|
39
|
+
"latency":2
|
40
|
+
},
|
41
|
+
"high":{
|
42
|
+
"backlog":0,
|
43
|
+
"latency":0
|
44
|
+
},
|
45
|
+
"low":{
|
46
|
+
"backlog":533,
|
47
|
+
"latency":54
|
48
|
+
}
|
49
|
+
},
|
50
|
+
"processes":[
|
51
|
+
{
|
52
|
+
"hostname":"kip1.example.com",
|
53
|
+
"pid":23324,
|
54
|
+
"queues":[
|
55
|
+
"high"
|
56
|
+
],
|
57
|
+
"concurrency":5,
|
58
|
+
"busy":2
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"hostname":"kip2.example.com",
|
62
|
+
"pid":23390,
|
63
|
+
"queues":[
|
64
|
+
"default",
|
65
|
+
"low"
|
66
|
+
],
|
67
|
+
"concurrency":5,
|
68
|
+
"busy":5
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
It will return a `queues` hash and a `processes` array.
|
75
|
+
|
76
|
+
The `queues` hash contains the existing queues with their names, the backlog
|
77
|
+
and the latency. The backlog is the amount of jobs waiting to be processed,
|
78
|
+
and the latency is the maximum time (in seconds) a job has been waiting in
|
79
|
+
the queue.
|
80
|
+
|
81
|
+
The `processes` array returns useful information about each sidekiq process.
|
82
|
+
The `concurrency`, in Sidekiq terms, is the maximum jobs a process can go
|
83
|
+
through in parallel. The `busy` is how many of those are in use.
|
84
|
+
|
85
|
+
If you plan on using this for your monitoring, the `latency` is a much
|
86
|
+
better metric than the `backlog`, and you can use the total `concurrency` and
|
87
|
+
total `busy` to know how much of your available workforce is in use.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sidekiq/api'
|
2
|
+
require 'sidekiq/web'
|
3
|
+
require 'sidekiq/monitor/web'
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module Monitor
|
7
|
+
class Stats
|
8
|
+
def queue_metrics
|
9
|
+
Sidekiq::Queue.all.each_with_object({}) do |queue, hash|
|
10
|
+
hash[queue.name] = {
|
11
|
+
backlog: queue.size,
|
12
|
+
latency: queue.latency.to_i
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_metrics
|
18
|
+
Sidekiq::ProcessSet.new.map do |process|
|
19
|
+
{
|
20
|
+
hostname: process['hostname'],
|
21
|
+
pid: process['pid'],
|
22
|
+
tag: process['tag'],
|
23
|
+
started_at: Time.at(process['started_at']),
|
24
|
+
queues: process['queues'],
|
25
|
+
labels: process['labels'],
|
26
|
+
concurrency: process['concurrency'],
|
27
|
+
busy: process['busy']
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Sidekiq::Web.register(Sidekiq::Monitor::Web)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sidekiq/monitor/stats'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Monitor
|
5
|
+
module Web
|
6
|
+
def self.registered(app)
|
7
|
+
app.get "/monitor-stats" do
|
8
|
+
monitor_stats = Monitor::Stats.new
|
9
|
+
|
10
|
+
content_type :json
|
11
|
+
Sidekiq.dump_json(
|
12
|
+
queues: monitor_stats.queue_metrics,
|
13
|
+
processes: monitor_stats.process_metrics
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sidekiq-monitor-stats"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Albert Llop"]
|
9
|
+
spec.email = ["albert@getharvest.com"]
|
10
|
+
spec.summary = %q{Add an endpoint to your running application that is running Sidekiq that returns useful data in JSON format.}
|
11
|
+
spec.homepage = "https://github.com/harvesthq/sidekiq-monitor-stats"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "minitest", ">= 5.0.0"
|
22
|
+
spec.add_development_dependency "sinatra"
|
23
|
+
spec.add_development_dependency "rack-test"
|
24
|
+
spec.add_development_dependency "mocha"
|
25
|
+
spec.add_dependency "sidekiq"
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Sidekiq::Monitor::StatsTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
Sidekiq.redis { |conn| conn.flushdb }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_returns_empty_data
|
9
|
+
assert_equal({}, stats.queue_metrics)
|
10
|
+
assert_equal([], stats.process_metrics)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_with_some_data
|
14
|
+
Sidekiq.redis do |conn|
|
15
|
+
@started_at = Time.now
|
16
|
+
|
17
|
+
conn.sadd("queues", "default")
|
18
|
+
conn.lpush("queue:default", Sidekiq.dump_json('enqueued_at' => @started_at.to_f))
|
19
|
+
|
20
|
+
conn.sadd('processes', 'foo:1234')
|
21
|
+
|
22
|
+
process_stats = {
|
23
|
+
hostname: 'foo',
|
24
|
+
pid: 1234,
|
25
|
+
tag: 'default',
|
26
|
+
started_at: Time.now.to_f,
|
27
|
+
queues: ['default'],
|
28
|
+
labels: ['reliable'],
|
29
|
+
concurrency: 25
|
30
|
+
}
|
31
|
+
|
32
|
+
conn.hmset('foo:1234', 'info', Sidekiq.dump_json(process_stats), 'at', @started_at.to_f, 'busy', 4)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal({ backlog: 1, latency: 0 }, stats.queue_metrics['default'])
|
36
|
+
|
37
|
+
process = stats.process_metrics.first
|
38
|
+
assert_equal "foo", process[:hostname]
|
39
|
+
assert_equal 1234, process[:pid]
|
40
|
+
assert_equal 'default', process[:tag]
|
41
|
+
assert_equal ['default'], process[:queues]
|
42
|
+
assert_equal ['reliable'], process[:labels]
|
43
|
+
assert_equal 25, process[:concurrency]
|
44
|
+
assert_equal 4, process[:busy]
|
45
|
+
assert_in_delta @started_at, process[:started_at], 0.01
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def stats
|
51
|
+
Sidekiq::Monitor::Stats.new
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
class Sidekiq::Monitor::WebTest < Minitest::Test
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Sidekiq.redis { |conn| conn.flushdb }
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_monitor_stats_empty
|
12
|
+
get '/monitor-stats'
|
13
|
+
|
14
|
+
assert_equal 200, last_response.status
|
15
|
+
|
16
|
+
body = Sidekiq.load_json(last_response.body)
|
17
|
+
assert_equal({}, body['queues'])
|
18
|
+
assert_equal([], body['processes'])
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_monitor_stats_with_some_data
|
22
|
+
Sidekiq::Monitor::Stats.any_instance.expects(
|
23
|
+
queue_metrics: { 'default' => { 'backlog' => 5, 'latency' => 10 } },
|
24
|
+
process_metrics: [
|
25
|
+
'hostname' => 'kip.local',
|
26
|
+
'pid' => '12345',
|
27
|
+
'queues' => ['default', 'high'],
|
28
|
+
'concurrency'=> 25,
|
29
|
+
'busy' => 4
|
30
|
+
]
|
31
|
+
)
|
32
|
+
get '/monitor-stats'
|
33
|
+
|
34
|
+
assert_equal 200, last_response.status
|
35
|
+
|
36
|
+
body = Sidekiq.load_json(last_response.body)
|
37
|
+
assert_equal 5, body['queues']['default']['backlog']
|
38
|
+
assert_equal 10, body['queues']['default']['latency']
|
39
|
+
|
40
|
+
assert_equal 1, body['processes'].size
|
41
|
+
process = body['processes'].first
|
42
|
+
assert_equal 'kip.local', process['hostname']
|
43
|
+
assert_equal '12345', process['pid']
|
44
|
+
assert_equal ['default','high'], process['queues']
|
45
|
+
assert_equal 25, process['concurrency']
|
46
|
+
assert_equal 4, process['busy']
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def app
|
52
|
+
Sidekiq::Web
|
53
|
+
end
|
54
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-monitor-stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Albert Llop
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sidekiq
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- albert@getharvest.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/sidekiq/monitor/stats.rb
|
125
|
+
- lib/sidekiq/monitor/web.rb
|
126
|
+
- sidekiq-monitor-stats.gemspec
|
127
|
+
- test/sidekiq-monitor-stats_test.rb
|
128
|
+
- test/sidekiq-monitor-web_test.rb
|
129
|
+
- test/test_helper.rb
|
130
|
+
homepage: https://github.com/harvesthq/sidekiq-monitor-stats
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.2.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Add an endpoint to your running application that is running Sidekiq that
|
154
|
+
returns useful data in JSON format.
|
155
|
+
test_files:
|
156
|
+
- test/sidekiq-monitor-stats_test.rb
|
157
|
+
- test/sidekiq-monitor-web_test.rb
|
158
|
+
- test/test_helper.rb
|