<commit_before>module Sidekiq
  module Instrumental
    module Middleware
      class Server < Base
        protected

        def track(stats, worker_instance, msg, queue, elapsed)
          submit_general_stats(stats)

          return unless config.allowed_to_submit queue, worker_instance

          base_key = "sidekiq.#{queue.to_s}."

          increment(base_key + 'processed')
          gauge(base_key + 'time', elapsed)
          gauge(base_key + 'enqueued', stats.queues[queue].to_i)
          base_key += msg['class'].underscore.gsub('/', '_') + '.'

          increment(base_key + 'processed')
          increment(base_key + 'time', elapsed)
        end

        def submit_general_stats(stats)
          increment("sidekiq.processed")
          {
              enqueued: nil,
              failed: nil,
              scheduled_size: 'scheduled'
          }.each do |method, name|
            gauge("sidekiq.#{(name || method).to_s}", stats.send(method).to_i)
          end
        end
      end
    end
  end
end<commit_msg>add latency<commit_after>module Sidekiq
  module Instrumental
    module Middleware
      class Server < Base
        protected

        def track(stats, worker_instance, msg, queue, elapsed)
          submit_general_stats(stats)

          return unless config.allowed_to_submit queue, worker_instance

          base_key = "sidekiq.#{queue.to_s}."

          increment(base_key + 'processed')
          gauge(base_key + 'time', elapsed)
          gauge(base_key + 'enqueued', stats.queues[queue].to_i)
          guage(base_key + 'latency', Sidekiq::Queue.new(queue.to_s).latency)
          base_key += msg['class'].underscore.gsub('/', '_') + '.'

          increment(base_key + 'processed')
          increment(base_key + 'time', elapsed)
        end

        def submit_general_stats(stats)
          increment("sidekiq.processed")
          {
              enqueued: nil,
              failed: nil,
              scheduled_size: 'scheduled'
          }.each do |method, name|
            gauge("sidekiq.#{(name || method).to_s}", stats.send(method).to_i)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11116279069767442, 'fraction_numerical': 0.0, 'mean_word_length': 2.0424328147100423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002862', 'n_tokens_mistral': 649, 'n_tokens_neox': 629, 'n_words': 127}