@@ -18,6 +18,7 @@ def self.allow_pid_label
1818
1919 DURATION_BUCKETS = [ 5 , 10 , 30 , 60 , 300 , 600 , 890 ] . freeze
2020 CONNECTION_DURATION_BUCKETS = [ 0.001 , 0.005 , 0.01 , 0.05 , 0.1 , 0.5 , 1 , 5 , 10 ] . freeze
21+ DELAYED_JOB_METRIC_BUCKETS = [ 0.01 , 0.05 , 0.1 , 0.5 , 1 , 2 , 5 , 10 , 30 , 60 , 120 , 300 , 600 ] . freeze
2122
2223 METRICS = [
2324 { type : :gauge , name : :cc_job_queues_length_total , docstring : 'Job queues length of worker processes' , labels : [ :queue ] , aggregation : :most_recent } ,
@@ -67,13 +68,19 @@ def self.allow_pid_label
6768 buckets : CONNECTION_DURATION_BUCKETS }
6869 ] . freeze
6970
71+ DELAYED_JOB_METRICS = [
72+ { type : :histogram , name : :cc_job_pickup_delay_seconds , docstring : 'Job pickup time (from enqueue to start)' , labels : %i[ queue worker ] , buckets : DELAYED_JOB_METRIC_BUCKETS } ,
73+ { type : :histogram , name : :cc_job_duration_seconds , docstring : 'Job processing time (start to finish)' , labels : %i[ queue worker ] , buckets : DELAYED_JOB_METRIC_BUCKETS }
74+ ] . freeze
75+
7076 def initialize ( registry : Prometheus ::Client . registry , cc_worker : false )
7177 self . class . allow_pid_label
7278
7379 @registry = registry
7480
7581 # Register all metrics, to initialize them for discoverability
7682 DB_CONNECTION_POOL_METRICS . each { |metric | register ( metric ) }
83+ DELAYED_JOB_METRICS . each { |metric | register ( metric ) }
7784
7885 return if cc_worker
7986
@@ -98,8 +105,8 @@ def increment_counter_metric(metric)
98105 @registry . get ( metric ) . increment
99106 end
100107
101- def update_histogram_metric ( metric , value )
102- @registry . get ( metric ) . observe ( value )
108+ def update_histogram_metric ( metric , value , labels : { } )
109+ @registry . get ( metric ) . observe ( value , labels : )
103110 end
104111
105112 def update_summary_metric ( metric , value )
0 commit comments