-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Adding Shoryuken metrics (#104)
* Adding Shoryuken metrics * fixed build check * added namespace resolution operator for shoryuken shutdown * adding unit tests for shoryuken metrics * changed false case in shoryuken unit test * included custom lables * adding Errno::ECONNRESET
- Loading branch information
rajkumar kandasami
committed
Jan 29, 2020
1 parent
c433c81
commit 4e143c8
Showing
8 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module PrometheusExporter::Instrumentation | ||
class Shoryuken | ||
|
||
def initialize(client: nil) | ||
@client = client || PrometheusExporter::Client.default | ||
end | ||
|
||
def call(worker, queue, msg, body) | ||
success = false | ||
start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) | ||
result = yield | ||
success = true | ||
result | ||
rescue ::Shoryuken::Shutdown => e | ||
shutdown = true | ||
raise e | ||
ensure | ||
duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start | ||
@client.send_json( | ||
type: "shoryuken", | ||
queue: queue, | ||
name: worker.class.name, | ||
success: success, | ||
shutdown: shutdown, | ||
duration: duration | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module PrometheusExporter::Server | ||
class ShoryukenCollector < TypeCollector | ||
|
||
def type | ||
"shoryuken" | ||
end | ||
|
||
def collect(obj) | ||
default_labels = { job_name: obj['name'] , queue_name: obj['queue'] } | ||
custom_labels = obj['custom_labels'] | ||
labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels) | ||
|
||
ensure_shoryuken_metrics | ||
@shoryuken_job_duration_seconds.observe(obj["duration"], labels) | ||
@shoryuken_jobs_total.observe(1, labels) | ||
@shoryuken_restarted_jobs_total.observe(1, labels) if obj["shutdown"] | ||
@shoryuken_failed_jobs_total.observe(1, labels) if !obj["success"] && !obj["shutdown"] | ||
end | ||
|
||
def metrics | ||
if @shoryuken_jobs_total | ||
[ | ||
@shoryuken_job_duration_seconds, | ||
@shoryuken_jobs_total, | ||
@shoryuken_restarted_jobs_total, | ||
@shoryuken_failed_jobs_total, | ||
] | ||
else | ||
[] | ||
end | ||
end | ||
|
||
protected | ||
|
||
def ensure_shoryuken_metrics | ||
if !@shoryuken_jobs_total | ||
|
||
@shoryuken_job_duration_seconds = | ||
PrometheusExporter::Metric::Counter.new( | ||
"shoryuken_job_duration_seconds", "Total time spent in shoryuken jobs.") | ||
|
||
@shoryuken_jobs_total = | ||
PrometheusExporter::Metric::Counter.new( | ||
"shoryuken_jobs_total", "Total number of shoryuken jobs executed.") | ||
|
||
@shoryuken_restarted_jobs_total = | ||
PrometheusExporter::Metric::Counter.new( | ||
"shoryuken_restarted_jobs_total", "Total number of shoryuken jobs that we restarted because of a shoryuken shutdown.") | ||
|
||
@shoryuken_failed_jobs_total = | ||
PrometheusExporter::Metric::Counter.new( | ||
"shoryuken_failed_jobs_total", "Total number of failed shoryuken jobs.") | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters