<commit_before>module CoppereggAgents

  class Plugin
    include InterruptibleSleep

    def initialize
    end

    def run(server, frequency)
      child_pid = fork do
        ['INT', 'TERM'].each { |sig| trap(sig) {
          Thread.new { interrupt } if !@interrupted
        } }

        retry_delay = frequency
        metric_identifier = metric_identifier(server)
        begin
          until interrupted? do
            data = monitor(server)
            CoppereggAgents.logger.debug "#{name} #{metric_identifier}: Data: #{data}"
            CopperEgg::MetricSample.save(name, metric_identifier, Time.now.to_i, data)
            retry_delay = frequency
            interruptible_sleep frequency
          end
        rescue => e
          CoppereggAgents.logger.error "#{name} #{metric_identifier}: Error getting data: #{e.inspect}"
          interruptible_sleep retry_delay
          retry_delay += frequency if retry_delay < frequency * 10
          retry
        end
      end
    end

    def interrupt
      CoppereggAgents.logger.info "Interrupting plugin process #{Process.pid}"
      @interrupted = true
      interrupt_sleep
    end
<commit_msg>Substract monitoring-time from sleep-time<commit_after>module CoppereggAgents

  class Plugin
    include InterruptibleSleep

    def initialize
    end

    def run(server, frequency)
      child_pid = fork do
        ['INT', 'TERM'].each { |sig| trap(sig) {
          Thread.new { interrupt } if !@interrupted
        } }

        retry_delay = frequency
        metric_identifier = metric_identifier(server)
        begin
          until interrupted? do
            time = Time.now
            data = monitor(server)
            CoppereggAgents.logger.debug "#{name} #{metric_identifier}: Data: #{data}"
            CopperEgg::MetricSample.save(name, metric_identifier, Time.now.to_i, data)
            retry_delay = frequency
            interruptible_sleep (frequency - (Time.now - time))
          end
        rescue => e
          CoppereggAgents.logger.error "#{name} #{metric_identifier}: Error getting data: #{e.inspect}"
          interruptible_sleep retry_delay
          retry_delay += frequency if retry_delay < frequency * 10
          retry
        end
      end
    end

    def interrupt
      CoppereggAgents.logger.info "Interrupting plugin process #{Process.pid}"
      @interrupted = true
      interrupt_sleep
    end

{'fraction_non_alphanumeric': 0.08277870216306156, 'fraction_numerical': 0.0016638935108153079, 'mean_word_length': 2.21954484605087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5645076', 'n_tokens_mistral': 659, 'n_tokens_neox': 640, 'n_words': 165}