57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/sidekiq/metrics/tracking.rb', line 57
def flush(time = Time.now)
totals, jobs, grams = reset
procd = totals["p"]
fails = totals["f"]
return if procd == 0 && fails == 0
now = time.utc
nowmid = now.strftime("%y%m%d|%-H:%M")[0..-2]
nowshort = now.strftime("%y%m%d|%-H:%M")
count = 0
redis do |conn|
if grams.size > 0
conn.pipelined do |pipe|
grams.each do |_, gram|
gram.persist(pipe, now)
end
end
end
[
["j", jobs, nowmid, MID_TERM],
["j", jobs, nowshort, SHORT_TERM]
].each do |prefix, data, bucket, ttl|
conn.pipelined do |xa|
stats = "#{prefix}|#{bucket}"
data.each_pair do |key, value|
xa.hincrby stats, key, value
count += 1
end
xa.expire(stats, ttl)
end
end
logger.debug "Flushed #{count} metrics"
count
end
end
|