<commit_before>
# The base class for SystemMetrics collectors.
#
# Some collects inherit directly from Collector, and some inherit from MultiCollector.
# The difference: if you're collecting for an arbitrary number of instances (say, disks), use MultiCollector.
# Otherwise, use Collector.
#
# Relative to Scout's plugins, Collectors have a few differences:
#
# 1. simplified: no options parsing. simpler interface to reporting and memory (these methods only take a hash)
# 2. intended to persist in memory: a collector maintains its own memory. Reuse the same instance as many times as needed.
#    If you need to persist to disk, use the to_hash and from_hash methods.
#
module ServerMetrics
  class Collector
    attr_reader :collector_id
    attr_accessor :data, :error

    def initialize(options={})
      @options = options
      @data={}
      @memory={}
      @collector_id = self.class.name+'-'+@options.to_a.sort_by { |a| a.first }.flatten.join('-')
      @error=nil
    end

    def option(name)
      @options[name] || @options[name.is_a?(String) ? name.to_sym : String(name)]
    end

    def run
      @data={}
      build_report
      @data
    end

    def report(hash)
      @data.merge!(hash)
    end

    #   memory(:no_track)
    #   memory.delete(:no_track)
    #   memory.clear
    #
    def memory(name = nil)
      if name.nil?
        @memory<commit_msg>collector backwards compatibility<commit_after>
# The base class for SystemMetrics collectors.
#
# Some collects inherit directly from Collector, and some inherit from MultiCollector.
# The difference: if you're collecting for an arbitrary number of instances (say, disks), use MultiCollector.
# Otherwise, use Collector.
#
# Relative to Scout's plugins, Collectors have a few differences:
#
# 1. simplified: no options parsing. simpler interface to reporting and memory (these methods only take a hash)
# 2. intended to persist in memory: a collector maintains its own memory. Reuse the same instance as many times as needed.
#    If you need to persist to disk, use the to_hash and from_hash methods.
#
module ServerMetrics
  class Collector
    attr_reader :collector_id
    attr_accessor :data, :error

    def initialize(options={})
      @options = options
      @data={}
      @memory={}
      @collector_id = self.class.name+'-'+@options.to_a.sort_by { |a| a.first.to_s }.flatten.join('-')
      @error=nil
    end

    def option(name)
      @options[name] || @options[name.is_a?(String) ? name.to_sym : String(name)]
    end

    def run
      @data={}
      build_report
      @data
    end

    def report(hash)
      @data.merge!(hash)
    end

    #   memory(:no_track)
    #   memory.delete(:no_track)
    #   memory.clear
    #
    def memory(name = nil)
      if name.nil?
        @memory
{'fraction_non_alphanumeric': 0.09730700179533214, 'fraction_numerical': 0.001436265709156194, 'mean_word_length': 3.061224489795918, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4309224', 'n_tokens_mistral': 862, 'n_tokens_neox': 821, 'n_words': 289}