FEATURE: Track timestamp of longest running sidekiq job

FEATURE: Track timestamp of longest running sidekiq job

diff --git a/lib/collector.rb b/lib/collector.rb
index a246c4e..d881bc2 100644
--- a/lib/collector.rb
+++ b/lib/collector.rb
@@ -157,6 +157,11 @@ module ::DiscoursePrometheus
         "Whether or not Sidekiq is paused"
       )
 
+      global_metrics << Gauge.new(
+        "sidekiq_oldest_running_job",
+        "Start timestamp for the oldest running sidekiq job"
+      )
+
       global_metrics << Gauge.new(
         "missing_s3_uploads",
         "Number of missing uploads in S3"
diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
index 3fd320b..e884a0f 100644
--- a/lib/internal_metric/global.rb
+++ b/lib/internal_metric/global.rb
@@ -17,6 +17,7 @@ module DiscoursePrometheus::InternalMetric
       :sidekiq_jobs_enqueued,
       :sidekiq_processes,
       :sidekiq_paused,
+      :sidekiq_oldest_running_job,
       :missing_post_uploads,
       :missing_s3_uploads,
       :version
@@ -67,6 +68,8 @@ module DiscoursePrometheus::InternalMetric
         stats
       end
 
+      @sidekiq_oldest_running_job = Sidekiq::Workers.new.map { |_, _, w| w["run_at"] }.min
+
       @sidekiq_processes = (Sidekiq::ProcessSet.new.size || 0) rescue 0
       @sidekiq_paused = sidekiq_paused_states

GitHub sha: 88339e49

1 Like