sidekiq-job-stats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c148c5169ea6f50b247b115078189ca2c87507c594828f1265ff0712a5f36df8
4
+ data.tar.gz: b16336e276fbe2f4602cb42c35790e6ab782e268422eb9275c3cc3a17e7cde3b
5
+ SHA512:
6
+ metadata.gz: c9e90f74596e40c2dc88365a2538a819096e6588043b756824debde4671cf8b1272299b7a920bf1ff840c6caee5f01346144dfd1083f32424d7df6aacd298137
7
+ data.tar.gz: 1ed3d23f01d593171a46c51a98d48f3b7cfec84577b7ba151de9cd8a7e42af2f928ce1f84c775beb5acd395770a9f385904e149db272be0a8bca0bcfc091584c
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at isliusar@liaisonedu.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sidekiq-job-stats.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sidekiq-job-stats (0.1.0)
5
+ get_process_mem
6
+ sidekiq (>= 6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ concurrent-ruby (1.2.2)
12
+ connection_pool (2.4.1)
13
+ ffi (1.15.5)
14
+ get_process_mem (0.2.7)
15
+ ffi (~> 1.0)
16
+ rack (2.2.7)
17
+ rake (13.0.6)
18
+ redis-client (0.17.0)
19
+ connection_pool
20
+ sidekiq (7.1.5)
21
+ concurrent-ruby (< 2)
22
+ connection_pool (>= 2.3.0)
23
+ rack (>= 2.2.4)
24
+ redis-client (>= 0.14.0)
25
+
26
+ PLATFORMS
27
+ arm64-darwin-21
28
+
29
+ DEPENDENCIES
30
+ rake (~> 13.0)
31
+ sidekiq-job-stats!
32
+
33
+ BUNDLED WITH
34
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 isliusar
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,11 @@
1
+ # Sidekiq::Job::Stats
2
+
3
+ ## Installation
4
+
5
+ Requires sidekiq '> 6.0'
6
+
7
+ In your Gemfile add:
8
+
9
+ ```ruby
10
+ gem 'sidekiq-job-stats'
11
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,77 @@
1
+ module SidekiqJobStats
2
+ class Duration
3
+ JOB_DURATION_PERIOD_EXPIRE = { :day => 60 * 60 * 24, :month => 60 * 60 * 24 * 30 }
4
+
5
+ attr_accessor :job_class
6
+
7
+ def initialize(job_class)
8
+ @job_class = job_class
9
+ end
10
+
11
+ def track(duration)
12
+ jobs_track_duration(duration, :day)
13
+ jobs_track_duration(duration, :month)
14
+ end
15
+
16
+ def jobs_track_duration(duration, period)
17
+ total, count, peak, _avg = jobs_duration_per(period)
18
+
19
+ Sidekiq.redis do |conn|
20
+ conn.set(
21
+ jobs_duration_period_key(period),
22
+ [
23
+ total.to_f + duration,
24
+ count.to_i + 1,
25
+ [peak.to_f, duration].max,
26
+ (total.to_f + duration)/(count.to_i + 1)
27
+ ].to_json)
28
+ conn.expire(jobs_duration_period_key(period), JOB_DURATION_PERIOD_EXPIRE[period])
29
+ end
30
+ end
31
+
32
+ def jobs_performed_day
33
+ _total, count, _peak, _avg = jobs_duration_per(:day)
34
+ count
35
+ end
36
+
37
+ def jobs_performed_month
38
+ _total, count, _peak, _avg = jobs_duration_per(:month)
39
+ count
40
+ end
41
+
42
+ def job_rolling_avg_day
43
+ _total, _count, _peak, avg = jobs_duration_per(:day)
44
+ avg
45
+ end
46
+
47
+ def job_rolling_avg_month
48
+ _total, _count, _peak, avg = jobs_duration_per(:month)
49
+ avg
50
+ end
51
+
52
+ def longest_job_day
53
+ _total, _count, peak, _avg = jobs_duration_per(:day)
54
+ peak
55
+ end
56
+
57
+ def longest_job_month
58
+ _total, _count, peak, _avg = jobs_duration_per(:month)
59
+ peak
60
+ end
61
+
62
+ def jobs_duration_per(period)
63
+ Sidekiq.redis do |conn|
64
+ JSON.parse(conn.get(jobs_duration_period_key(period)) || "null")
65
+ end
66
+ end
67
+
68
+ def jobs_duration_key
69
+ "stats:jobs:#{job_class}:duration"
70
+ end
71
+
72
+ def jobs_duration_period_key(period)
73
+ "#{jobs_duration_key}:#{period}:#{Time.now.send(period)}"
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,27 @@
1
+ module SidekiqJobStats
2
+ class Enqueued
3
+ attr_accessor :job_class
4
+
5
+ def initialize(job_class)
6
+ @job_class = job_class
7
+ end
8
+
9
+ def track
10
+ Sidekiq.redis do |conn|
11
+ conn.incr(job_stats_enqueued_key)
12
+ end
13
+ end
14
+
15
+ def jobs_enqueued
16
+ Sidekiq.redis do |conn|
17
+ conn.get(job_stats_enqueued_key).to_i
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def job_stats_enqueued_key
24
+ "stats:jobs:#{job_class}:stats"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module SidekiqJobStats
2
+ module Helpers
3
+ module Stats
4
+ def stat_header(stat_name)
5
+ "<th class='header'>" + stat_name.to_s.gsub(/_/,' ').capitalize + "</th>"
6
+ end
7
+
8
+ def display_stat(stat, stat_name, format)
9
+ formatted_stat = self.send(format, stat.send(stat_name))
10
+ "<td>#{formatted_stat}</td>"
11
+ end
12
+
13
+ def time_display(float)
14
+ float.blank? ? "" : ("%.2f" % float.to_s) + "s"
15
+ end
16
+
17
+ def number_display(num)
18
+ num.blank? ? "" : num
19
+ end
20
+
21
+ def mb_display(num)
22
+ num.blank? ? "" : "#{num}MB"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ module SidekiqJobStats
2
+ class History
3
+ attr_accessor :job_class
4
+
5
+ def initialize(job_class)
6
+ @job_class = job_class
7
+ end
8
+
9
+ def track(job_data)
10
+ push_history(job_data)
11
+ end
12
+
13
+ def histories_recordable
14
+ @histories_recordable || 100
15
+ end
16
+
17
+ def job_histories(start = 0, limit = 100)
18
+ Sidekiq.redis do |conn|
19
+ conn.lrange(job_history_key, start, start + limit - 1).map { |h| JSON.parse(h) }
20
+ end
21
+ end
22
+
23
+ def histories_recorded
24
+ Sidekiq.redis do |conn|
25
+ conn.llen(job_history_key)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def job_history_key
32
+ "stats:jobs:#{job_class}:history"
33
+ end
34
+
35
+ def push_history(job_data)
36
+ return if Sidekiq.history_max_count.zero?
37
+
38
+ Sidekiq.redis do |conn|
39
+ conn.lpush(job_history_key, job_data.to_json)
40
+ conn.ltrim(job_history_key, 0, Sidekiq.history_max_count)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+
@@ -0,0 +1,68 @@
1
+ module SidekiqJobStats
2
+ class MemoryUsage
3
+ MEMORY_PERIOD_EXPIRE = {:day => 60 * 60 * 24, :month => 60 * 60 * 24 * 30}
4
+
5
+ attr_accessor :job_class
6
+
7
+ def initialize(job_class)
8
+ @job_class = job_class
9
+ end
10
+
11
+ def track
12
+ memory_usage = GetProcessMem.new.mb.round(2)
13
+
14
+ job_memory_usage_increx_per(memory_usage, :day)
15
+ job_memory_usage_increx_per(memory_usage, :month)
16
+ end
17
+
18
+ def job_memory_usage_increx_per(memory_usage, period)
19
+ total, count, peak, _avg = job_memory_usage_per(period)
20
+ Sidekiq.redis do |conn|
21
+ conn.set(
22
+ job_memory_usage_period_key(period),
23
+ [
24
+ total.to_f + memory_usage,
25
+ count.to_i + 1,
26
+ [peak.to_f, memory_usage].max,
27
+ ((total.to_f + memory_usage)/(count.to_i + 1)).round(2)
28
+ ].to_json)
29
+ conn.expire(job_memory_usage_period_key(period), MEMORY_PERIOD_EXPIRE[period])
30
+ end
31
+ end
32
+
33
+ def job_memory_usage_avg_day
34
+ _total, _count, _peak, avg = job_memory_usage_per(:day)
35
+ avg
36
+ end
37
+
38
+ def job_memory_usage_avg_month
39
+ _total, _count, _peak, avg = job_memory_usage_per(:month)
40
+ avg
41
+ end
42
+
43
+ def peak_memory_usage_day
44
+ _total, _count, peak, _avg = job_memory_usage_per(:day)
45
+ peak
46
+ end
47
+
48
+ def peak_memory_usage_month
49
+ _total, _count, peak, _avg = job_memory_usage_per(:month)
50
+ peak
51
+ end
52
+
53
+ def job_memory_usage_per(period)
54
+ Sidekiq.redis do |conn|
55
+ JSON.parse(conn.get(job_memory_usage_period_key(period)) || "null")
56
+ end
57
+ end
58
+
59
+ def job_memory_usage_period_key(period)
60
+ "#{jobs_memory_usage_key}:#{period}:#{Time.now.send(period)}"
61
+ end
62
+
63
+ def jobs_memory_usage_key
64
+ "stats:jobs:#{job_class}:memory_usage"
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,42 @@
1
+ require 'sidekiq/component'
2
+ require_relative 'duration'
3
+ require_relative 'enqueued'
4
+ require_relative 'memory_usage'
5
+
6
+ module SidekiqJobStats
7
+ class Middleware
8
+ include Sidekiq::Component
9
+
10
+ def call(_worker, msg, queue)
11
+ data = {
12
+ enqueued_at: msg['enqueued_at'], started_at: Time.now, payload: msg['args'], status: 'success',
13
+ exception: '', queue: queue
14
+ }
15
+
16
+ begin
17
+ yield
18
+ rescue StandardError => e
19
+ data[:status] = 'failed'
20
+ data[:exception] = e.message
21
+ raise e
22
+ ensure
23
+ data[:finished_at] = Time.now
24
+ data[:duration] = data[:finished_at] - data[:started_at]
25
+ push_stats(data, msg['class'])
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def push_stats(data, job_class)
32
+ Duration.new(job_class).track(data[:duration])
33
+ Enqueued.new(job_class).track
34
+ MemoryUsage.new(job_class).track
35
+ History.new(job_class).track(data)
36
+ end
37
+
38
+ def sidekiq_job_class
39
+ @sidekiq_job_class ||= Sidekiq::JobRecord
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ module SidekiqJobStats
2
+ class Statistic
3
+
4
+ # DEFAULT_STATS = [:jobs_enqueued, :jobs_performed_day, :jobs_performed_month,
5
+ # :job_rolling_avg_day, :job_rolling_avg_month,
6
+ # :longest_job_day, :longest_job_month, :job_memory_usage_avg_day,
7
+ # :job_memory_usage_avg_month, :peak_memory_usage_day,
8
+ # :peak_memory_usage_month]
9
+
10
+ attr_accessor :job_class
11
+
12
+ delegate :jobs_enqueued, to: :enqueued
13
+ delegate :jobs_performed_day, :jobs_performed_month, :job_rolling_avg_day, :job_rolling_avg_month,
14
+ :longest_job_day, :longest_job_month, to: :duration
15
+ delegate :job_memory_usage_avg_day, :job_memory_usage_avg_month, :peak_memory_usage_day,
16
+ :peak_memory_usage_month, to: :memory_usage
17
+ delegate :job_histories, :histories_recorded, to: :history
18
+ delegate :name, to: :job_class
19
+
20
+ def self.find_all
21
+ all_jobs_classes.map{|j| new(j)}
22
+ end
23
+
24
+ def self.all_jobs_classes
25
+ subclasses = []
26
+ ObjectSpace.each_object(Class) do |sub_class|
27
+ next unless sub_class < Sidekiq::Worker
28
+ subclasses << sub_class
29
+ end
30
+ subclasses
31
+ end
32
+
33
+ def initialize(job_class)
34
+ self.job_class = job_class
35
+ end
36
+
37
+ %w[duration memory_usage history enqueued].each do |method_name|
38
+ define_method(method_name) do
39
+ instance_variable_get("@#{method_name}") ||
40
+ instance_variable_set("@#{method_name}", Object.const_get("SidekiqJobStats::" + method_name.camelize).new(job_class))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqJobStats
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'helpers/stats'
2
+ require_relative 'duration'
3
+ require_relative 'enqueued'
4
+
5
+ module SidekiqJobStats
6
+ module WebExtension
7
+ ROOT = File.expand_path('../web', __dir__)
8
+
9
+ def self.registered(app)
10
+ app.helpers Helpers::Stats
11
+
12
+ app.get '/history' do
13
+ ApplicantScoringWorker #todo
14
+ @jobs = SidekiqJobStats::Statistic.find_all.sort
15
+
16
+ render(:erb, File.read("#{ROOT}/views/job_stats.erb"))
17
+ end
18
+
19
+ app.get '/history/job_history/:job_class' do
20
+ ApplicantScoringWorker #todo
21
+ @job_class = SidekiqJobStats::Statistic.find_all.find { |j| j.job_class.to_s == params[:job_class] }
22
+
23
+ @start = 0
24
+ @start = params[:start].to_i if params[:start]
25
+ @limit = 100
26
+ @limit = params[:limit].to_i if params[:limit]
27
+
28
+ @histories = @job_class.job_histories(@start, @limit)
29
+ @size = @job_class.histories_recorded
30
+
31
+ render(:erb, File.read("#{ROOT}/views/job_histories.erb"))
32
+ end
33
+
34
+ app.settings.locales << File.expand_path('locales', ROOT)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sidekiq_job_stats/version"
4
+ require_relative "sidekiq_job_stats/middleware"
5
+ require_relative "sidekiq_job_stats/web_extension"
6
+ require_relative "sidekiq_job_stats/statistic"
7
+ require_relative "sidekiq_job_stats/enqueued"
8
+ require_relative "sidekiq_job_stats/history"
9
+
10
+ require 'sidekiq/web'
11
+
12
+ module Sidekiq
13
+ def self.history_max_count=(value)
14
+ @history_max_count = value
15
+ end
16
+
17
+ def self.history_max_count
18
+ @history_max_count || 1000
19
+ end
20
+ end
21
+
22
+ Sidekiq::Web.register(SidekiqJobStats::WebExtension)
23
+ Sidekiq::Web.tabs['History'] = 'history'
@@ -0,0 +1,43 @@
1
+ <h1>Sidekiq Job Histories</h1>
2
+
3
+ <p class="intro">
4
+ This page displays histories of jobs that have been executed.
5
+ </p>
6
+ <h2><%= @job_class.job_class.to_s %></h2>
7
+
8
+ <table class="table table-hover table-bordered table-striped">
9
+ <tr>
10
+ <th class="header">Enqueued time</th>
11
+ <th class="header">Started at</th>
12
+ <th class="header">Finished at</th>
13
+ <th class="header">Duration</th>
14
+ <th class="header">Arguments</th>
15
+ <th class="header">Success</th>
16
+ <th class="header">Exception</th>
17
+ </tr>
18
+ <% @histories.each do |history| %>
19
+ <% if history.is_a? Hash %>
20
+ <tr>
21
+ <td><span class="time"><%= Time.at(history["enqueued_at"]) %></span></td>
22
+ <td><span class="time"><%= history["started_at"] %></span></td>
23
+ <td><span class="time"><%= history["finished_at"]%></span></td>
24
+ <td><%= history["duration"] %>s</td>
25
+ <td><%= history["payload"] %></td>
26
+ <td><%= history["status"] %></td>
27
+ <td><%= history["exception"] if history["exception"] %></td>
28
+ </tr>
29
+ <% end %>
30
+ <% end %>
31
+ </table>
32
+
33
+ <%if @start > 0 || @start + @limit <= @size %>
34
+ <p class='pagination'>
35
+ <% if @start - @limit >= 0 %>
36
+ <a href="<%= current_page %>?start=<%= [0, @start - @limit].max %>&limit=<%= @limit %>" class='less'>&laquo; less</a>
37
+ <% end %>
38
+ <% if @start + @limit <= @size %>
39
+ <a href="<%= current_page %>?start=<%= @start + @limit %>&limit=<%= @limit %>" class='more'>more &raquo;</a>
40
+ <% end %>
41
+ </p>
42
+ <%end%>
43
+
@@ -0,0 +1,48 @@
1
+
2
+ <h1>Sidekiq Job Stats</h1>
3
+
4
+ <p class="intro">
5
+ This page displays statistics about jobs that have been executed.
6
+ </p>
7
+
8
+ <div class="fixTableHead">
9
+ <table class="table table-hover table-bordered table-striped">
10
+ <thead class="fixedHeader">
11
+ <tr>
12
+ <th class="header">Name</th>
13
+ <%= stat_header(:jobs_enqueued) %>
14
+ <%= stat_header(:jobs_performed_day) %>
15
+ <%= stat_header(:jobs_performed_month) %>
16
+ <%= stat_header(:job_rolling_avg_day) %>
17
+ <%= stat_header(:job_rolling_avg_month) %>
18
+ <%= stat_header(:longest_job_day) %>
19
+ <%= stat_header(:longest_job_month) %>
20
+ <%= stat_header(:job_memory_usage_avg_day) %>
21
+ <%= stat_header(:job_memory_usage_avg_month) %>
22
+ <%= stat_header(:peak_memory_usage_day) %>
23
+ <%= stat_header(:peak_memory_usage_month) %>
24
+ </tr>
25
+ </thead>
26
+ <tbody class="scrollContent">
27
+ <% @jobs.each do |job| %>
28
+ <tr>
29
+ <td>
30
+ <%= job.name %>
31
+ <a href='<%= "/sidekiq/history/job_history/#{job.name}" %>'>[history]</a>
32
+ </td>
33
+ <%= display_stat(job, :jobs_enqueued, :number_display) %>
34
+ <%= display_stat(job, :jobs_performed_day, :number_display) %>
35
+ <%= display_stat(job, :jobs_performed_month, :number_display) %>
36
+ <%= display_stat(job, :job_rolling_avg_day, :time_display) %>
37
+ <%= display_stat(job, :job_rolling_avg_month, :time_display) %>
38
+ <%= display_stat(job, :longest_job_day, :time_display) %>
39
+ <%= display_stat(job, :longest_job_month, :time_display) %>
40
+ <%= display_stat(job, :job_memory_usage_avg_day, :mb_display) %>
41
+ <%= display_stat(job, :job_memory_usage_avg_month, :mb_display) %>
42
+ <%= display_stat(job, :peak_memory_usage_day, :mb_display) %>
43
+ <%= display_stat(job, :peak_memory_usage_month, :mb_display) %>
44
+ </tr>
45
+ <% end %>
46
+ </tbody>
47
+ </table>
48
+ </div>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/sidekiq_job_stats/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sidekiq-job-stats"
7
+ spec.version = SidekiqJobStats::VERSION
8
+ spec.authors = ["isliusar"]
9
+ spec.email = ["isliusar@liaisonedu.com"]
10
+
11
+ spec.summary = "Tracks jobs performed, failed, and the duration of the last 100 jobs for each job type."
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/sliusar-ihor/sidekiq-job-stats"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "sidekiq", ">= 6"
34
+ spec.add_dependency "get_process_mem"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,8 @@
1
+ module Sidekiq
2
+ module Job
3
+ module Stats
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-job-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - isliusar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: get_process_mem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Tracks jobs performed, failed, and the duration of the last 100 jobs
42
+ for each job type.
43
+ email:
44
+ - isliusar@liaisonedu.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/sidekiq_job_stats.rb
56
+ - lib/sidekiq_job_stats/duration.rb
57
+ - lib/sidekiq_job_stats/enqueued.rb
58
+ - lib/sidekiq_job_stats/helpers/stats.rb
59
+ - lib/sidekiq_job_stats/history.rb
60
+ - lib/sidekiq_job_stats/memory_usage.rb
61
+ - lib/sidekiq_job_stats/middleware.rb
62
+ - lib/sidekiq_job_stats/statistic.rb
63
+ - lib/sidekiq_job_stats/version.rb
64
+ - lib/sidekiq_job_stats/web_extension.rb
65
+ - lib/web/views/job_histories.erb
66
+ - lib/web/views/job_stats.erb
67
+ - sidekiq-job-stats.gemspec
68
+ - sig/sidekiq/job/stats.rbs
69
+ homepage: https://github.com/sliusar-ihor/sidekiq-job-stats
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/sliusar-ihor/sidekiq-job-stats
74
+ source_code_uri: https://github.com/sliusar-ihor/sidekiq-job-stats
75
+ changelog_uri: https://github.com/sliusar-ihor/sidekiq-job-stats
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.4.10
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Tracks jobs performed, failed, and the duration of the last 100 jobs for
95
+ each job type.
96
+ test_files: []