sidekiq_history 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +52 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/lib/sidekiq-history.rb +1 -0
- data/lib/sidekiq/history.rb +43 -0
- data/lib/sidekiq/history/charts.rb +43 -0
- data/lib/sidekiq/history/configuration.rb +11 -0
- data/lib/sidekiq/history/log_parser.rb +37 -0
- data/lib/sidekiq/history/middleware.rb +63 -0
- data/lib/sidekiq/history/statistic.rb +78 -0
- data/lib/sidekiq/history/statistic/redis_statistic.rb +36 -0
- data/lib/sidekiq/history/statistic/runtime_statistic.rb +56 -0
- data/lib/sidekiq/history/version.rb +5 -0
- data/lib/sidekiq/history/views/history.erb +55 -0
- data/lib/sidekiq/history/views/history.js +144 -0
- data/lib/sidekiq/history/views/sidekiq-history.css +56 -0
- data/lib/sidekiq/history/views/worker.erb +62 -0
- data/lib/sidekiq/history/web_extension.rb +92 -0
- data/sidekiq-history.gemspec +30 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce17dda04d989f42f80e18f01b548dff2366be0c
|
4
|
+
data.tar.gz: 007c79a03d2a6fb28ac4993b95b17ec227215ef8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ade2b45e0afc02dda422e7f892614fe3d37af710ac61cf0b6cebde504718b487a3b86b6182a605ce90529bdd0ca05c2cf18560005b6fae597c1f8b4e7267641
|
7
|
+
data.tar.gz: bf7e0fa8d9f45691b34fddbe7fbf1fcaee0a9a68b0e57583aa7ea8fa75aa793ed61b45afbe2bfbdbdb2a732217ca7175cd59becc01cc76166bd86fc1f16c57c1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
services:
|
5
|
+
- redis-server
|
6
|
+
rvm:
|
7
|
+
- 2.1
|
8
|
+
- 2.0.0
|
9
|
+
- 2.2
|
10
|
+
- jruby-19mode
|
11
|
+
- jruby
|
12
|
+
- rbx-2
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: rbx-2
|
16
|
+
- rvm: jruby
|
17
|
+
bundler_args: --without test --jobs 3 --retry 3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
* 13.05.2015: Add ability to change any date range on any history page
|
2
|
+
|
3
|
+
*Anton Davydov*
|
4
|
+
* 12.05.2015: Add last job status data parameter for each worker
|
5
|
+
|
6
|
+
*Anton Davydov*
|
7
|
+
* 11.05.2015: Add page woth worker data table for each day
|
8
|
+
|
9
|
+
*Anton Davydov*
|
10
|
+
* 28.04.2015: Formating worker date in web UI
|
11
|
+
|
12
|
+
*Anton Davydov*
|
13
|
+
* 27.04.2015: Set specific color for any worker
|
14
|
+
|
15
|
+
*Anton Davydov*
|
16
|
+
* 10.04.2015: Add search field on worker page
|
17
|
+
|
18
|
+
*Anton Davydov*
|
19
|
+
* 04.04.2015: Fix livereload button in index page
|
20
|
+
|
21
|
+
*Anton Davydov*
|
22
|
+
* 23.03.2015: Add max runtime column to worker web table
|
23
|
+
|
24
|
+
*Anton Davydov*
|
25
|
+
* 19.03.2015: Add functionality for adding custom css and js files to web page
|
26
|
+
|
27
|
+
*Anton Davydov*
|
28
|
+
* 18.03.2015: Add configuration class with log_file options
|
29
|
+
|
30
|
+
*Anton Davydov*
|
31
|
+
* 16.03.2015: Add worker page where user can see log for this worker
|
32
|
+
|
33
|
+
*Anton Davydov*
|
34
|
+
* 15.03.2015: Add worker statistic table to index history page
|
35
|
+
|
36
|
+
*Anton Davydov*
|
37
|
+
* 08.03.2015: Add charts for each passed and failed jobs for each worker.
|
38
|
+
|
39
|
+
*Anton Davydov*
|
40
|
+
* 08.03.2015: Add Statistic class which provide statistics
|
41
|
+
for each day and each worker.
|
42
|
+
|
43
|
+
Sidekiq::History::Statistic.new(0).workers_hash
|
44
|
+
# =>[{"2015-03-07"=>{"HistoryWorker"=>{:failed=>1, :passed=>1}}}]
|
45
|
+
|
46
|
+
*Anton Davydov*
|
47
|
+
* 08.03.2015: Save in redis json with failed and passed jobs for each worker.
|
48
|
+
|
49
|
+
*Anton Davydov*
|
50
|
+
* 04.03.2015: Created simple midelware and static page.
|
51
|
+
|
52
|
+
*Anton Davydov*
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Anton Davydov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sidekiq::History
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/davydovanton/sidekiq-history.svg?branch=master)](https://travis-ci.org/davydovanton/sidekiq-history) [![Code Climate](https://codeclimate.com/github/davydovanton/sidekiq-history/badges/gpa.svg)](https://codeclimate.com/github/davydovanton/sidekiq-history) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/davydovanton/sidekiq-history?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
4
|
+
|
5
|
+
Improved display of statistics for your workers and jobs statistic
|
6
|
+
|
7
|
+
**This gem work only with sidekiq version more than [3.3.4](https://github.com/mperham/sidekiq/releases/tag/v3.3.4)**
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'sidekiq-history'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install sidekiq-history
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
Open in your browser `/sidekiq/history` page.
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
Sidekiq history gem have `log_file` option. This option lets you specify a custom path to sidekiq log file. By default this option equal `log/sidekiq.log`
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
Sidekiq::History.configure do |config|
|
30
|
+
config.log_file = 'test/helpers/logfile.log'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
1. Fork it ( https://github.com/davydovanton/sidekiq-history/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sidekiq/history"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sidekiq/history'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
begin
|
2
|
+
require 'sidekiq/web'
|
3
|
+
rescue LoadError
|
4
|
+
# client-only usage
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'sidekiq/api'
|
8
|
+
require 'sidekiq/history/charts'
|
9
|
+
require 'sidekiq/history/configuration'
|
10
|
+
require 'sidekiq/history/log_parser'
|
11
|
+
require 'sidekiq/history/middleware'
|
12
|
+
require 'sidekiq/history/statistic/redis_statistic'
|
13
|
+
require 'sidekiq/history/statistic/runtime_statistic'
|
14
|
+
require 'sidekiq/history/statistic'
|
15
|
+
require 'sidekiq/history/version'
|
16
|
+
require 'sidekiq/history/web_extension'
|
17
|
+
|
18
|
+
module Sidekiq
|
19
|
+
module History
|
20
|
+
class << self
|
21
|
+
attr_writer :configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Sidekiq.configure_server do |config|
|
35
|
+
config.server_middleware do |chain|
|
36
|
+
chain.add Sidekiq::History::Middleware
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if defined?(Sidekiq::Web)
|
41
|
+
Sidekiq::Web.register Sidekiq::History::WebExtension
|
42
|
+
Sidekiq::Web.tabs['History'] = 'history'
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module History
|
3
|
+
class Charts
|
4
|
+
def initialize(days_previous, start_date = nil)
|
5
|
+
@start_date = start_date || Time.now.utc.to_date
|
6
|
+
@end_date = @start_date - days_previous
|
7
|
+
end
|
8
|
+
|
9
|
+
def information_for(type)
|
10
|
+
redis_statistic.worker_names.map do |worker|
|
11
|
+
color = color_for(worker)
|
12
|
+
{
|
13
|
+
label: worker,
|
14
|
+
fillColor: "rgba(#{color},0.2)",
|
15
|
+
strokeColor: "rgba(#{color},0.9)",
|
16
|
+
pointColor: "rgba(#{color},0.2)",
|
17
|
+
pointStrokeColor: '#fff',
|
18
|
+
pointHighlightFill: '#fff',
|
19
|
+
pointHighlightStroke: 'rgba(220,220,220,1)',
|
20
|
+
data: redis_statistic.for_worker(worker).map{ |val| val.fetch(type, 0) }
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def color_for(worker)
|
26
|
+
Digest::MD5.hexdigest(worker)[0..5]
|
27
|
+
.scan(/../)
|
28
|
+
.map{ |color| color.to_i(16) }
|
29
|
+
.join ','
|
30
|
+
end
|
31
|
+
|
32
|
+
def dates
|
33
|
+
@dates ||= redis_statistic.hash.flat_map(&:keys)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def redis_statistic
|
39
|
+
RedisStatistic.new(@start_date, @end_date)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module History
|
3
|
+
# Heroku have read only file system. See more in this link:
|
4
|
+
# https://devcenter.heroku.com/articles/read-only-filesystem
|
5
|
+
class LogParser
|
6
|
+
def initialize(worker_name)
|
7
|
+
@worker_name = worker_name
|
8
|
+
@logfile = log_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
return [] unless File.exists?(@logfile)
|
13
|
+
|
14
|
+
File.open(@logfile).map do |line|
|
15
|
+
line_hash(line) if line[/\W?#@worker_name\W?/]
|
16
|
+
end.compact
|
17
|
+
end
|
18
|
+
|
19
|
+
def line_hash(line)
|
20
|
+
{ color: color(line), text: line.sub(/\n/, '') }
|
21
|
+
end
|
22
|
+
|
23
|
+
def color(line)
|
24
|
+
case
|
25
|
+
when line.include?('done') then 'green'
|
26
|
+
when line.include?('start') then 'yellow'
|
27
|
+
when line.include?('fail') then 'red'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def log_file
|
33
|
+
Sidekiq.options[:logfile] || Sidekiq::History.configuration.log_file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module History
|
3
|
+
class Middleware
|
4
|
+
attr_accessor :msg
|
5
|
+
|
6
|
+
def call(worker, msg, queue, &block)
|
7
|
+
call_with_sidekiq_history(worker, msg, queue, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def call_with_sidekiq_history(worker, msg, queue)
|
13
|
+
worker_status = new_status
|
14
|
+
start = Time.now.utc
|
15
|
+
|
16
|
+
yield
|
17
|
+
rescue StandardError => e
|
18
|
+
worker_status[:failed] = 1
|
19
|
+
worker_status[:passed] = 0
|
20
|
+
worker_status[:last_job_status] = 'failed'.freeze
|
21
|
+
|
22
|
+
raise e
|
23
|
+
ensure
|
24
|
+
worker_status[:runtime] ||= [elapsed(start)]
|
25
|
+
worker_status[:last_runtime] = Time.now.utc
|
26
|
+
worker_status[:last_job_status] ||= 'passed'.freeze
|
27
|
+
|
28
|
+
save_entry_for_worker(worker_status, worker)
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_status
|
32
|
+
# worker.sidekiq_options_hash
|
33
|
+
{
|
34
|
+
failed: 0,
|
35
|
+
passed: 1
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def save_entry_for_worker(worker_status, worker)
|
40
|
+
Sidekiq.redis do |redis|
|
41
|
+
history = "sidekiq:history:#{Time.now.utc.to_date}"
|
42
|
+
value = redis.hget(history, worker.class.to_s)
|
43
|
+
|
44
|
+
if value
|
45
|
+
summary = Sidekiq.load_json(value).symbolize_keys
|
46
|
+
[:failed, :passed, :runtime].each do |stat|
|
47
|
+
worker_status[stat] = summary[stat] + worker_status[stat]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
redis.hset(history, worker.class.to_s, Sidekiq.dump_json(worker_status))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# this methos already exist in Sidekiq::Middleware::Server::Logging class
|
58
|
+
def elapsed(start)
|
59
|
+
(Time.now.utc - start).to_f.round(3)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module History
|
3
|
+
class Statistic
|
4
|
+
JOB_STATES = [:passed, :failed]
|
5
|
+
|
6
|
+
def initialize(days_previous, start_date = nil)
|
7
|
+
@start_date = start_date || Time.now.utc.to_date
|
8
|
+
@end_date = @start_date - days_previous
|
9
|
+
end
|
10
|
+
|
11
|
+
def display
|
12
|
+
redis_statistic.worker_names.map do |worker|
|
13
|
+
{
|
14
|
+
name: worker,
|
15
|
+
last_job_status: last_job_status_for(worker),
|
16
|
+
number_of_calls: number_of_calls(worker),
|
17
|
+
runtime: runtime_statistic(worker).values_hash
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def display_pre_day(worker_name)
|
23
|
+
redis_statistic.hash.flat_map do |day|
|
24
|
+
day.reject{ |_, workers| workers.empty? }.map do |date, workers|
|
25
|
+
worker_data = workers[worker_name]
|
26
|
+
next unless worker_data
|
27
|
+
|
28
|
+
{
|
29
|
+
date: date,
|
30
|
+
failure: worker_data[:failed],
|
31
|
+
success: worker_data[:passed],
|
32
|
+
total: worker_data[:failed] + worker_data[:passed],
|
33
|
+
last_job_status: worker_data[:last_job_status],
|
34
|
+
runtime: runtime_for_day(worker_name, worker_data)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end.compact.reverse
|
38
|
+
end
|
39
|
+
|
40
|
+
def runtime_for_day(worker_name, worker_data)
|
41
|
+
runtime_statistic(worker_name, worker_data[:runtime])
|
42
|
+
.values_hash
|
43
|
+
.merge!(last: worker_data[:last_runtime])
|
44
|
+
end
|
45
|
+
|
46
|
+
def number_of_calls(worker)
|
47
|
+
number_of_calls = JOB_STATES.map{ |state| number_of_calls_for state, worker }
|
48
|
+
|
49
|
+
{
|
50
|
+
success: number_of_calls.first,
|
51
|
+
failure: number_of_calls.last,
|
52
|
+
total: number_of_calls.inject(:+)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def number_of_calls_for(state, worker)
|
57
|
+
redis_statistic.for_worker(worker)
|
58
|
+
.select(&:any?)
|
59
|
+
.map{ |hash| hash[state] }.inject(:+) || 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def last_job_status_for(worker)
|
63
|
+
redis_statistic
|
64
|
+
.for_worker(worker)
|
65
|
+
.select(&:any?)
|
66
|
+
.last[:last_job_status]
|
67
|
+
end
|
68
|
+
|
69
|
+
def runtime_statistic(worker, values = nil)
|
70
|
+
RuntimeStatistic.new(redis_statistic, worker, values)
|
71
|
+
end
|
72
|
+
|
73
|
+
def redis_statistic
|
74
|
+
RedisStatistic.new(@start_date, @end_date)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|