From 375adfa8f4ed8d96d9b0e4ab3844fa274f7ff234 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 16 Mar 2020 10:35:52 +0000 Subject: Added automagic longboat_meta_raider_runtime metric --- lib/longboat/raiders.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/longboat/raiders.rb') diff --git a/lib/longboat/raiders.rb b/lib/longboat/raiders.rb index 103cac5..e27ac0b 100644 --- a/lib/longboat/raiders.rb +++ b/lib/longboat/raiders.rb @@ -2,7 +2,7 @@ module Longboat class Raiders def initialize(collector, config) @collector = collector - @raiders = [] + @raiders = {} @config = config @config[:raiders_path].each do |dir| @@ -15,13 +15,26 @@ module Longboat cname = reqname.split('_').map(&:capitalize).join require "raiders/#{reqname}" - @raiders << Kernel.const_get(cname).new(@collector, raider_config) + @raiders[reqname] = Kernel.const_get(cname).new(@collector, raider_config) end end end def raid! - @raiders.each(&:raid) + @raiders.each do |name, raider| + start_time = Time.now + raider.raid + end_time = Time.now + time_taken = end_time - start_time + + @collector.report!( + "longboat_meta_raider_runtime", + (time_taken.to_f * 1000).to_i, + help: "Time taken by a raider whilst raiding in ms", + type: "guage", + labels: {raider: name} + ) + end end def raid_every(time = @config[:raid_every], async = true) -- cgit v1.2.1