-
Notifications
You must be signed in to change notification settings - Fork 7
/
active_job.rb
51 lines (46 loc) · 986 Bytes
/
active_job.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
module Telegraf
# 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.
#
class ActiveJob
include Plugin
def initialize(series: 'active_job', **kwargs)
super
end
def call(_name, start, finish, _id, payload)
job = payload[:job]
point = Point.new(
tags: {
**@tags,
job: job.class.name,
queue: job.queue_name,
errors: payload.key?(:exception_object),
},
values: {
app_ms: ((finish - start) * 1000.0), # milliseconds
},
)
_write(point, before_send_kwargs: {payload: payload})
end
end
end