Class: Telegraf::ActiveJob

Inherits:
Object
  • Object
show all
Defined in:
lib/telegraf/active_job.rb

Overview

Telegraf::ActiveJob

This class collects ActiveJob queue metrics and sends them to telegraf.

Tags:

  • ‘queue`:

    The queue this job landed on.
    
  • ‘job`:

    The name of the job class that was executed.
    
  • ‘errors`:

    Whether or not this job errored.
    

Values:

  • ‘app_ms`:

    Total job processing time.
    

Instance Method Summary collapse

Constructor Details

#initialize(agent:, series: 'active_job', tags: {}) ⇒ ActiveJob

Returns a new instance of ActiveJob.



27
28
29
30
31
# File 'lib/telegraf/active_job.rb', line 27

def initialize(agent:, series: 'active_job', tags: {})
  @agent = agent
  @series = series.to_s.freeze
  @tags = tags.freeze
end

Instance Method Details

#call(_name, start, finish, _id, payload) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/telegraf/active_job.rb', line 33

def call(_name, start, finish, _id, payload)
  job = payload[:job]

  @agent.write(
    @series,
    tags: {
      **@tags,
      job: job.class.name,
      queue: job.queue_name,
      errors: payload.key?(:exception_object)
    },
    values: {
      app_ms: ((finish - start) * 1000.0) # milliseconds
    }
  )
end