diff options
| author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-16 10:35:52 +0000 | 
|---|---|---|
| committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-16 10:35:52 +0000 | 
| commit | 375adfa8f4ed8d96d9b0e4ab3844fa274f7ff234 (patch) | |
| tree | dc2fde7fcb96775fc695582f4c0147883cd90ced | |
| parent | 666ea91e473554acabe6f6c3477eb915e70a7538 (diff) | |
Added automagic longboat_meta_raider_runtime metric
| -rw-r--r-- | lib/longboat/collector.rb | 1 | ||||
| -rw-r--r-- | lib/longboat/raiders.rb | 19 | 
2 files changed, 17 insertions, 3 deletions
| diff --git a/lib/longboat/collector.rb b/lib/longboat/collector.rb index 765adee..10e2f84 100644 --- a/lib/longboat/collector.rb +++ b/lib/longboat/collector.rb @@ -25,6 +25,7 @@ module Longboat      def prometheus_metrics        res = ""        @metrics.each do |name, metric| +        res << ?\n unless res.empty?          res << "#HELP #{name} #{metric[:help]}\n" unless metric[:help].nil?          res << "#TYPE #{name} #{metric[:type]}\n" unless metric[:type].nil? 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) | 
