yabeda-resque 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc64c43baf725df7a5f4691a877bf32907d1b2416bdd6835dbe1c43f002d7a01
4
- data.tar.gz: e72afe1ba6efb66cca854f9f093a230e434450afcfa87c230eeee9aba29a046f
3
+ metadata.gz: 92a9da462531ecfb518643959d19f16b3c1be6a046e007b6b15a5e2d2750d807
4
+ data.tar.gz: 534ff3806d35238cc01b55a25b80ab56ba1b654f5922ccf5258a1bc749577261
5
5
  SHA512:
6
- metadata.gz: 3acc9b46978e547bf10fbee16bdc0cd5053d9d8bbe710e0c7353ab79a0cfd577eed7547e0e05a6aee9e78040ac85c46fed4fbb4cfca8160e490de1c1d4fece9f
7
- data.tar.gz: 85e7422c3cd1ecc4835de4ae1c5ff3438fac117ab22ad873242ee962e8ff42296aacf41ee186c4344e549c1842c4741f15c7e20b1ccb6197f66e261ca0da4423
6
+ metadata.gz: 22e5a853e3f3859ad67eeedc58805fd6a2c2f1223aaf4f3ebca0ccc1053e69fe95c33385aa9416c2c9ff5ee2bf7e587ca12605bd63d8ed369dbb9095188481b0
7
+ data.tar.gz: '031385be1e5fbf72ea6d80fe1a928d504018b11b604b364f3d5a243db2b4145a26f09ae655712641c239cc75fd7c3537067a3761e7c287d3c6c6518254bcb185'
data/CHANGELOG.md CHANGED
@@ -1,14 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.1.0] - 2025-02-4
3
+ ## [1.2.0] - 2025-05-16
4
+ - Add jobs_processing_oldest_age metric with unit as config option
5
+
6
+ ## [1.1.0] - 2025-02-14
4
7
  - Fix: queue_sizes metric not being exported
5
8
 
6
- ## [1.0.0] - 2025-02-4
9
+ ## [1.0.0] - 2025-02-14
7
10
  - Add queue_size metric
8
11
  - Add jobs_delayed metric for resque-scheduler
9
12
 
10
13
  ## [0.1.0] - 2025-02-13
11
-
12
14
  - Add jobs_pending metric
13
15
  - Add jobs_processed metric
14
16
  - Add jobs_failed metric
data/README.md CHANGED
@@ -22,16 +22,24 @@ Add the following code to your existing Yabeda setup:
22
22
  Yabeda::Resque.install!
23
23
  ```
24
24
 
25
+ ## Configuration
26
+
27
+ Configuration can be passed to the `Yabeda::Resque.install!` method, e.g.: `Yabeda::Resque.install!(option_name: :value)` The following options are available:
28
+
29
+ * `jobs_processing_oldest_age_unit`:
30
+ The unit of the `jobs_processing_oldest_age` metric. This can be set to `:seconds`, `:minutes`, `:hours` or `:days`. The default value is nil, which means the metric is turned off and will not collected.
31
+
25
32
  ## Provided metrics
26
33
 
27
- | Metric name | Type | Tags | Description |
28
- |-------------------|-------|--------------|-------------------------------------|
29
- | `jobs_pending` | gauge | none | Number of jobs in all queues |
30
- | `jobs_processed` | gauge | none | Number of jobs processed |
31
- | `jobs_failed` | gauge | none | Number of jobs currently failed |
32
- | `workers_total` | gauge | none | Number of workers |
33
- | `workers_working` | gauge | none | Number of workers currently working |
34
- | `queue_sizes` | gauge | queue (name) | Number of jobs in a specific queue |
34
+ | Metric name | Type | Tags | Description |
35
+ |-------------------|-------|----------|------------------------------------------------------|
36
+ | `jobs_pending` | gauge | none | Number of jobs in all queues |
37
+ | `jobs_processed` | gauge | none | Number of jobs processed |
38
+ | `jobs_failed` | gauge | none | Number of jobs currently failed |
39
+ | `workers_total` | gauge | none | Number of workers |
40
+ | `workers_working` | gauge | none | Number of workers currently working |
41
+ | `queue_sizes` | gauge | queue (name) | Number of jobs in a specific queue |
42
+ | `jobs_processing_oldest_age` | gauge | none | Age of the oldest processing job (unit configurable) |
35
43
 
36
44
  Yabeda::Resque detects if [resque-scheduler](https://github.com/resque/resque-scheduler) is being used and adds the following metrics:
37
45
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Resque
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
data/lib/yabeda/resque.rb CHANGED
@@ -8,11 +8,37 @@ require "resque"
8
8
  module Yabeda
9
9
  module Resque
10
10
  class << self
11
+ DEFAULT_CONFIG = {
12
+ jobs_processing_oldest_age_unit: nil
13
+ }.freeze
14
+
11
15
  def monitor_delayed?
12
16
  defined?(::Resque::Scheduler)
13
17
  end
14
18
 
15
- def install!
19
+ def jobs_processing_oldest_age(config)
20
+ oldest_timestamp = ::Resque.working.map { |worker| worker.job(false)["run_at"] }.min
21
+ return 0 if oldest_timestamp.nil?
22
+ age_in_seconds = (Time.now - Time.parse(oldest_timestamp)).to_i
23
+ return 0 if age_in_seconds < 0
24
+
25
+ case config[:jobs_processing_oldest_age_unit]
26
+ when :seconds
27
+ age_in_seconds
28
+ when :minutes
29
+ age_in_seconds / 60.0
30
+ when :hours
31
+ age_in_seconds / 3600.0
32
+ when :days
33
+ age_in_seconds / 86_400.0
34
+ else
35
+ raise ArgumentError, "Unsupported time unit: #{unit.inspect}"
36
+ end
37
+ end
38
+
39
+ def install!(**config)
40
+ config = DEFAULT_CONFIG.merge(config)
41
+
16
42
  Yabeda.configure do
17
43
  group :resque do
18
44
  default_options = {aggregation: :most_recent}
@@ -20,6 +46,10 @@ module Yabeda
20
46
  gauge :jobs_processed, **default_options, comment: "Number of processed jobs"
21
47
  gauge :jobs_failed, **default_options, comment: "Number of failed jobs"
22
48
 
49
+ if config[:jobs_processing_oldest_age_unit]
50
+ gauge :jobs_processing_oldest_age, **default_options, comment: "How long the longest processing job has been running in #{config[:jobs_processing_oldest_age_unit]}"
51
+ end
52
+
23
53
  gauge :queue_sizes, tags: %i[queue], **default_options, comment: "Number of jobs in a specific queue"
24
54
 
25
55
  gauge :workers_total, **default_options, comment: "Number of workers"
@@ -37,6 +67,11 @@ module Yabeda
37
67
  resque.jobs_pending.set({}, resque_info[:pending])
38
68
  resque.jobs_processed.set({}, resque_info[:processed])
39
69
 
70
+ if config[:jobs_processing_oldest_age_unit]
71
+ value = ::Yabeda::Resque.jobs_processing_oldest_age(config)
72
+ resque.jobs_processing_oldest_age.set({}, value)
73
+ end
74
+
40
75
  if ::Yabeda::Resque.monitor_delayed?
41
76
  resque.jobs_delayed.set({}, ::Resque.count_all_scheduled_jobs)
42
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josch Bockler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2025-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.5.11
80
+ rubygems_version: 3.5.22
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Yabeda plugin to collect basic metrics for Resque backend jobs