@@ -21,59 +21,33 @@ module TypeCollectors
2121 ##
2222 # Collect resque data from collectors and parse them into metrics
2323 #
24- class Resque < PrometheusExporter :: Server :: TypeCollector
24+ class Resque < Bigcommerce :: Prometheus :: TypeCollectors :: Base
2525 ##
2626 # Initialize the collector
2727 #
28- def initialize
29- @workers_total = PrometheusExporter ::Metric ::Gauge . new ( 'resque_workers_total' , 'Number of active workers' )
30- @jobs_failed_total = PrometheusExporter ::Metric ::Gauge . new ( 'jobs_failed_total' , 'Number of failed jobs' )
31- @jobs_pending_total = PrometheusExporter ::Metric ::Gauge . new ( 'jobs_pending_total' , 'Number of pending jobs' )
32- @jobs_processed_total = PrometheusExporter ::Metric ::Gauge . new ( 'jobs_processed_total' , 'Number of processed jobs' )
33- @queues_total = PrometheusExporter ::Metric ::Gauge . new ( 'queues_total' , 'Number of total queues' )
34- @queue_sizes = PrometheusExporter ::Metric ::Gauge . new ( 'queue_sizes' , 'Size of each queue' )
35- end
36-
37- ##
38- # @return [String]
39- #
40- def type
41- 'resque'
42- end
43-
44- ##
45- # @return [Array]
46- #
47- def metrics
48- return [ ] unless @workers_total
49-
50- [
51- @workers_total ,
52- @jobs_failed_total ,
53- @jobs_pending_total ,
54- @jobs_processed_total ,
55- @queues_total ,
56- @queue_sizes
57- ]
28+ def build_metrics
29+ {
30+ workers_total : PrometheusExporter ::Metric ::Gauge . new ( 'resque_workers_total' , 'Number of active workers' ) ,
31+ jobs_failed_total : PrometheusExporter ::Metric ::Gauge . new ( 'jobs_failed_total' , 'Number of failed jobs' ) ,
32+ jobs_pending_total : PrometheusExporter ::Metric ::Gauge . new ( 'jobs_pending_total' , 'Number of pending jobs' ) ,
33+ jobs_processed_total : PrometheusExporter ::Metric ::Gauge . new ( 'jobs_processed_total' , 'Number of processed jobs' ) ,
34+ queues_total : PrometheusExporter ::Metric ::Gauge . new ( 'queues_total' , 'Number of total queues' ) ,
35+ queue_sizes : PrometheusExporter ::Metric ::Gauge . new ( 'queue_sizes' , 'Size of each queue' )
36+ }
5837 end
5938
6039 ##
6140 # Collect resque metrics from input data
6241 #
63- def collect ( obj )
64- default_labels = { environment : obj [ 'environment' ] }
65-
66- custom_labels = obj [ 'custom_labels' ]
67- labels = custom_labels . nil? ? default_labels : default_labels . merge ( custom_labels )
68-
69- @workers_total . observe ( obj [ 'workers_total' ] , labels )
70- @jobs_failed_total . observe ( obj [ 'jobs_failed_total' ] , labels )
71- @jobs_pending_total . observe ( obj [ 'jobs_pending_total' ] , labels )
72- @jobs_processed_total . observe ( obj [ 'jobs_processed_total' ] , labels )
73- @queues_total . observe ( obj [ 'queues_total' ] , labels )
74-
75- obj [ 'queues' ] . each do |name , size |
76- @queue_sizes . observe ( size , labels . merge ( queue : name ) )
42+ def collect_metrics ( data :, labels : { } )
43+ metric ( :workers_total ) . observe ( obj [ 'workers_total' ] , labels )
44+ metric ( :jobs_failed_total ) . observe ( obj [ 'jobs_failed_total' ] , labels )
45+ metric ( :jobs_pending_total ) . observe ( obj [ 'jobs_pending_total' ] , labels )
46+ metric ( :jobs_processed_total ) . observe ( obj [ 'jobs_processed_total' ] , labels )
47+ metric ( :queues_total ) . observe ( obj [ 'queues_total' ] , labels )
48+
49+ data [ 'queues' ] . each do |name , size |
50+ metric ( :queue_sizes ) . observe ( size , labels . merge ( queue : name ) )
7751 end
7852 end
7953 end
0 commit comments