<commit_before>require 'hadoop_metrics2/api'

module HBaseMetrics
  class RegionServer
    include HadoopMetrics2::API

    def extract_region(target)
      ret = {  'regions' => [] }
      target.each do |k,v|
        if /^Namespace_(\w+)_table_([\w\.\-]+)_region_(\w+)_metric_(\w+)$/ =~ k
          r = ret['regions'].select{  |i| i['namespace'] == $1 && i['table'] == $2 && i['region'] == $3}.first
          unless r
            r = {
            'namespace' => $1,
            'table' => $2,
            'region' => $3,
            }
            ret['regions'] << r
          end
          r[$4] = v
        else
          ret[k] = v
        end
      end

      ret
    end
    
    def server
      query_jmx("Hadoop:service=HBase,name=RegionServer,sub=Server").first
    end

    def regions
      disable_snake_case {  
        target = query_jmx("Hadoop:service=HBase,name=RegionServer,sub=Regions").first
        extract_region(target)
      }
    end
    
    def ipc
      query_jmx('Hadoop:service=HBase,name=RegionServer,sub=IPC').first
    end

  end
end<commit_msg>Add Metrics of HBase replication<commit_after>require 'hadoop_metrics2/api'

module HBaseMetrics
  class RegionServer
    include HadoopMetrics2::API

    def extract_region(target)
      ret = {  'regions' => [] }
      target.each do |k,v|
        if /^Namespace_(\w+)_table_([\w\.\-]+)_region_(\w+)_metric_(\w+)$/ =~ k
          r = ret['regions'].select{  |i| i['namespace'] == $1 && i['table'] == $2 && i['region'] == $3}.first
          unless r
            r = {
            'namespace' => $1,
            'table' => $2,
            'region' => $3,
            }
            ret['regions'] << r
          end
          r[$4] = v
        else
          ret[k] = v
        end
      end

      ret
    end
    
    def server
      query_jmx("Hadoop:service=HBase,name=RegionServer,sub=Server").first
    end

    def regions
      disable_snake_case {  
        target = query_jmx("Hadoop:service=HBase,name=RegionServer,sub=Regions").first
        extract_region(target)
      }
    end
    
    def ipc
      query_jmx('Hadoop:service=HBase,name=RegionServer,sub=IPC').first
    end

    def replication
      query_jmx("Hadoop:service=HBase,name=RegionServer,sub=Replication").first
    end
    
  end
end
{'fraction_non_alphanumeric': 0.14329268292682926, 'fraction_numerical': 0.0078397212543554, 'mean_word_length': 1.9562419562419562, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '503931', 'n_tokens_mistral': 781, 'n_tokens_neox': 757, 'n_words': 137}