gri 10.0.2 → 10.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gri/app_collector.rb +1 -1
- data/lib/gri/builtindefs.rb +6 -3
- data/lib/gri/main.rb +3 -3
- data/lib/gri/plugin.rb +6 -1
- data/lib/gri/plugin/docker_collector.rb +72 -0
- data/lib/gri/plugin/suppress_veth.rb +15 -0
- data/lib/gri/plugin/writer_influxdb.rb +66 -0
- data/lib/gri/polling_unit.rb +5 -1
- data/lib/gri/scheduler.rb +1 -0
- data/lib/gri/version.rb +1 -1
- data/test/test_docker_collector.rb +29 -0
- metadata +7 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: abd70d1091e31de3ab3f392bc49cf25bd7359752
         | 
| 4 | 
            +
              data.tar.gz: 4e2b0060b88f9ee99fe4735b707e950526f297ea
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1464140edec6d228c6c64b2b8634c322dd6f1c9723b586550cfb70b3c1d778441628fb1b64aa629a4a67a8220585ef2e037e6940a3a6755237f511ed6be8eec4
         | 
| 7 | 
            +
              data.tar.gz: d3a55bcf25504742047ca129a67f3cff38754c986c5942f881523425ea1a18af4457c2ef55950d231bd3c861a185edd270e7bd8b0d82f2c29a159cd4bed9b773
         | 
    
        data/lib/gri/app_collector.rb
    CHANGED
    
    | @@ -121,7 +121,7 @@ module GRI | |
| 121 121 | 
             
                def get_targets_from_lines lines, config
         | 
| 122 122 | 
             
                  targets = Config.get_targets_from_lines lines
         | 
| 123 123 | 
             
                  goptions = Config.parse_options(*(config.getvar 'option'))
         | 
| 124 | 
            -
                  goptions.merge!(Config.parse_options(*config | 
| 124 | 
            +
                  goptions.merge!(Config.parse_options(*config.getvar('O')))
         | 
| 125 125 | 
             
                  if config['host-pat']
         | 
| 126 126 | 
             
                    hosts_re = config.getvar('host-pat').map {|h| Regexp.new h}
         | 
| 127 127 | 
             
                    targets = targets.select {|host, | hosts_re.detect {|re| re === host}}
         | 
    
        data/lib/gri/builtindefs.rb
    CHANGED
    
    | @@ -59,14 +59,17 @@ module GRI | |
| 59 59 | 
             
                  :composite=>['s', 'v', 't'],
         | 
| 60 60 | 
             
                },
         | 
| 61 61 | 
             
                'ifMIB'=>{:cat=>'',
         | 
| 62 | 
            -
                  :oid=>['ifHCInOctets', 'ifHCOutOctets', 'ifHighSpeed', 'ifAlias'],
         | 
| 63 | 
            -
                  :fix_workhash=>proc {|wh|
         | 
| 62 | 
            +
                  :oid=>['ifName', 'ifHCInOctets', 'ifHCOutOctets', 'ifHighSpeed', 'ifAlias'],
         | 
| 63 | 
            +
                  :fix_workhash=>proc {|wh, options|
         | 
| 64 64 | 
             
                    for k, r in wh['']
         | 
| 65 65 | 
             
                      r['ifInOctets'] = r['ifHCInOctets'] if r['ifHCInOctets']
         | 
| 66 66 | 
             
                      r['ifOutOctets'] = r['ifHCOutOctets'] if r['ifHCOutOctets']
         | 
| 67 67 | 
             
                      if r['ifHighSpeed'] and r['ifHighSpeed'].to_i > 4000
         | 
| 68 68 | 
             
                        r['ifSpeed'] = r['ifHighSpeed'].to_i * 1_000_000
         | 
| 69 69 | 
             
                      end
         | 
| 70 | 
            +
                      if options['ifname'] and r['ifName']
         | 
| 71 | 
            +
                        r['ifDescr'] = r['ifName']
         | 
| 72 | 
            +
                      end
         | 
| 70 73 | 
             
                    end
         | 
| 71 74 | 
             
                  },
         | 
| 72 75 | 
             
                },
         | 
| @@ -84,7 +87,7 @@ module GRI | |
| 84 87 | 
             
                  :fix_workhash => lambda {|wh|
         | 
| 85 88 | 
             
                    ifrecord = wh[''] || {}
         | 
| 86 89 | 
             
                    for k, record in wh[:ipaddr]
         | 
| 87 | 
            -
                      a = k + '/' + record['mask']
         | 
| 90 | 
            +
                      a = k + '/' + (record['mask'] || '?')
         | 
| 88 91 | 
             
                      ind = record['ifIndex']
         | 
| 89 92 | 
             
                      if (r = ifrecord[ind])
         | 
| 90 93 | 
             
                        if r['ipaddr']
         | 
    
        data/lib/gri/main.rb
    CHANGED
    
    | @@ -26,9 +26,6 @@ module GRI | |
| 26 26 | 
             
                  @options.each {|k, v| @config.setvar k.to_s, v}
         | 
| 27 27 | 
             
                  root_dir = @config['root-dir'] ||= Config::ROOT_PATH
         | 
| 28 28 |  | 
| 29 | 
            -
                  plugin_dirs = @config.getvar('plugin-dir') || [root_dir + '/plugin']
         | 
| 30 | 
            -
                  GRI::Plugin.load_plugins plugin_dirs, @config
         | 
| 31 | 
            -
             | 
| 32 29 | 
             
                  log_dir = @config['log-dir'] || root_dir + '/log'
         | 
| 33 30 | 
             
                  begin
         | 
| 34 31 | 
             
                    Dir.mkdir log_dir unless File.exist? log_dir
         | 
| @@ -37,6 +34,9 @@ module GRI | |
| 37 34 | 
             
                  rescue SystemCallError
         | 
| 38 35 | 
             
                  end
         | 
| 39 36 |  | 
| 37 | 
            +
                  plugin_dirs = @config.getvar('plugin-dir') || [root_dir + '/plugin']
         | 
| 38 | 
            +
                  GRI::Plugin.load_plugins plugin_dirs, @config
         | 
| 39 | 
            +
             | 
| 40 40 | 
             
                  @config['tra-dir'] ||= root_dir + '/tra'
         | 
| 41 41 | 
             
                  @config['gra-dir'] ||= root_dir + '/gra'
         | 
| 42 42 | 
             
                end
         | 
    
        data/lib/gri/plugin.rb
    CHANGED
    
    | @@ -15,7 +15,12 @@ module GRI | |
| 15 15 | 
             
                  files.each {|fname|
         | 
| 16 16 | 
             
                    unless @loaded[fname]
         | 
| 17 17 | 
             
                      path = File.join dir, fname
         | 
| 18 | 
            -
                       | 
| 18 | 
            +
                      begin
         | 
| 19 | 
            +
                        require path
         | 
| 20 | 
            +
                      rescue LoadError
         | 
| 21 | 
            +
                        Log.error "LoadError: #{$!}"
         | 
| 22 | 
            +
                        puts "LoadError: #{$!}" if $debug
         | 
| 23 | 
            +
                      end
         | 
| 19 24 | 
             
                      @loaded[fname] = path
         | 
| 20 25 | 
             
                    end
         | 
| 21 26 | 
             
                  }
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            if Object.const_defined? :RUBY_VERSION
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'net/http'
         | 
| 6 | 
            +
            require 'json'
         | 
| 7 | 
            +
            require 'gri/collector'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module GRI
         | 
| 10 | 
            +
              class DockerCollector < Collector
         | 
| 11 | 
            +
                TYPES['docker'] = self
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def on_attach
         | 
| 14 | 
            +
                  now_i = Time.now.to_i
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  records = []
         | 
| 17 | 
            +
                  host = @hostname || @host
         | 
| 18 | 
            +
                  port = @options["docker-port"] || 2375
         | 
| 19 | 
            +
                  port = port.to_i
         | 
| 20 | 
            +
                  Net::HTTP.start(host, port) {|http|
         | 
| 21 | 
            +
                    res = http.get '/info'
         | 
| 22 | 
            +
                    if Net::HTTPSuccess === res
         | 
| 23 | 
            +
                      h = JSON.parse(res.body)
         | 
| 24 | 
            +
                      for k in ['Containers', 'Images',
         | 
| 25 | 
            +
                          'NEventsListener', 'NFd', 'NGoroutines']
         | 
| 26 | 
            +
                        record = {'_host'=>host, '_time'=>now_i,
         | 
| 27 | 
            +
                          '_key'=>"num_docker_#{k}", 'num'=>h[k],
         | 
| 28 | 
            +
                        }
         | 
| 29 | 
            +
                        records.push record
         | 
| 30 | 
            +
                      end
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    res = http.get '/containers/json'
         | 
| 34 | 
            +
                    if Net::HTTPSuccess === res
         | 
| 35 | 
            +
                      a = JSON.parse(res.body)
         | 
| 36 | 
            +
                      for c in a
         | 
| 37 | 
            +
                        if (cinfo = get_container_info(http, c['Id']))
         | 
| 38 | 
            +
                          docker_hostname = cinfo['Config']['Hostname']
         | 
| 39 | 
            +
                          docker_image = cinfo['Config']['Image']
         | 
| 40 | 
            +
                          metrics = cinfo['Metrics']
         | 
| 41 | 
            +
                          record = {'_host'=>host, '_time'=>now_i, '_interval'=>@interval,
         | 
| 42 | 
            +
                            '_key'=>"docker_#{docker_hostname}"
         | 
| 43 | 
            +
                          }
         | 
| 44 | 
            +
                          for mkey, mvalues in metrics
         | 
| 45 | 
            +
                            for k, v in mvalues
         | 
| 46 | 
            +
                              record[k] = v
         | 
| 47 | 
            +
                            end
         | 
| 48 | 
            +
                          end
         | 
| 49 | 
            +
                          records.push record
         | 
| 50 | 
            +
                        end
         | 
| 51 | 
            +
                      end
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
                  }
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  @cb.call records
         | 
| 56 | 
            +
                  @loop.detach self
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def get_container_info http, ctn_id
         | 
| 60 | 
            +
                  if Net::HTTPSuccess === (res = http.get "/containers/#{ctn_id}/json")
         | 
| 61 | 
            +
                    h = JSON.parse(res.body)
         | 
| 62 | 
            +
                    return h if h and h['Metrics']
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                  nil
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            rescue LoadError
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            GRI::DEFS['interfaces'].update :ignore? => proc {|record|
         | 
| 2 | 
            +
              /(^(|Loopback|Null|Async)\d+)|(^veth\w)|cef layer|atm subif/ ===
         | 
| 3 | 
            +
                record['ifDescr']
         | 
| 4 | 
            +
            },
         | 
| 5 | 
            +
              :exclude? => proc {|record|
         | 
| 6 | 
            +
              record['ifOperStatus'].to_i != 1 or
         | 
| 7 | 
            +
                record['ifSpeed'].to_i == 0 or
         | 
| 8 | 
            +
                (Integer(record['ifInOctets']) == 0 and
         | 
| 9 | 
            +
                 Integer(record['ifOutOctets']) == 0) or
         | 
| 10 | 
            +
                /(^(|Loopback|Null|Async|lo)\d+)|(^veth\w)|cef layer|atm subif/ ===
         | 
| 11 | 
            +
                record['ifDescr']
         | 
| 12 | 
            +
            },
         | 
| 13 | 
            +
              :hidden? => proc {|record|
         | 
| 14 | 
            +
              /(^veth\w)|cef layer|atm subif|unrouted.VLAN/ === record['ifDescr']
         | 
| 15 | 
            +
            }
         | 
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            require 'gri/writer'
         | 
| 2 | 
            +
            require 'gri/utils'
         | 
| 3 | 
            +
            require 'influxdb'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module GRI
         | 
| 6 | 
            +
              class InfluxdbWriter < Writer
         | 
| 7 | 
            +
                TYPES['influxdb'] = self
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                include Utils
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def initialize options={}
         | 
| 12 | 
            +
                  @options = options
         | 
| 13 | 
            +
                  database = 'gri'
         | 
| 14 | 
            +
                  host = options[:influxdb_host] || 'localhost'
         | 
| 15 | 
            +
                  username = options[:influxdb_username] || 'root'
         | 
| 16 | 
            +
                  password = options[:influxdb_password] || 'root'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  @db = InfluxDB::Client.new database, :host=>host,
         | 
| 19 | 
            +
                    :username=>username, :password=>password,
         | 
| 20 | 
            +
                    :time_precision=>'s'
         | 
| 21 | 
            +
                  dbs = @db.get_database_list
         | 
| 22 | 
            +
                  if (dbs.select {|h| h['name'] == 'gri'}).empty?
         | 
| 23 | 
            +
                    Log.info 'InfluxDB: create database'
         | 
| 24 | 
            +
                    @db.create_database 'gri'
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                  @buf = {}
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def write records
         | 
| 30 | 
            +
                  time = Time.now.to_i
         | 
| 31 | 
            +
                  for record in records
         | 
| 32 | 
            +
                    time = record.delete '_time'
         | 
| 33 | 
            +
                    #host = record.delete '_host'
         | 
| 34 | 
            +
                    key = record.delete '_key'
         | 
| 35 | 
            +
                    record.delete '_mtime'
         | 
| 36 | 
            +
                    record.delete '_interval'
         | 
| 37 | 
            +
                    data_name, index = parse_key key
         | 
| 38 | 
            +
                    next if data_name == 'SYS'
         | 
| 39 | 
            +
                    if data_name == ''
         | 
| 40 | 
            +
                      data_name = 'interfaces'
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                    record.update :time=>time.to_i, :key=>index
         | 
| 43 | 
            +
                    buffered_write data_name, record
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def buffered_write data_name, record
         | 
| 48 | 
            +
                  (ary = (@buf[data_name] ||= [])).push record
         | 
| 49 | 
            +
                  if ary.size > 1000
         | 
| 50 | 
            +
                    flush data_name, ary
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def flush data_name, ary
         | 
| 55 | 
            +
                  while (sa = ary.take 10000; ary[0, 10000] = []; !sa.empty?)
         | 
| 56 | 
            +
                    @db.write_point data_name, sa
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def finalize
         | 
| 61 | 
            +
                  for data_name, ary in @buf
         | 
| 62 | 
            +
                    flush data_name, ary
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
    
        data/lib/gri/polling_unit.rb
    CHANGED
    
    
    
        data/lib/gri/scheduler.rb
    CHANGED
    
    
    
        data/lib/gri/version.rb
    CHANGED
    
    
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'mock'
         | 
| 4 | 
            +
            require 'gri/plugin/docker_collector'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module GRI
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            class MockDockerCollector < DockerCollector
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            class TestDockerCollector < Test::Unit::TestCase
         | 
| 12 | 
            +
              def _test_docker_collector
         | 
| 13 | 
            +
                Collector::TYPES['docker'] = MockDockerCollector
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                host = 'dockerhost'
         | 
| 16 | 
            +
                options = {'type'=>'docker'}
         | 
| 17 | 
            +
                records = []
         | 
| 18 | 
            +
                collector = Collector.create(options['type'], host, options) {|rs|
         | 
| 19 | 
            +
                  records += rs
         | 
| 20 | 
            +
                }
         | 
| 21 | 
            +
                assert_kind_of DockerCollector, collector
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                s = '{"GitCommit":"28ff62e/0.7.9","GoVersion":"go1.2","KernelVersion":"2.6.32-999.9.abc.x86_64","Version":"0.7.9"}'
         | 
| 24 | 
            +
                collector.on_read s + "\n"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: gri
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 10.0. | 
| 4 | 
            +
              version: 10.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - maebashi
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-06-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: msgpack
         | 
| @@ -96,11 +96,14 @@ files: | |
| 96 96 | 
             
            - lib/gri/plugin.rb
         | 
| 97 97 | 
             
            - lib/gri/plugin/bootstrap.rb
         | 
| 98 98 | 
             
            - lib/gri/plugin/cisco.rb
         | 
| 99 | 
            +
            - lib/gri/plugin/docker_collector.rb
         | 
| 99 100 | 
             
            - lib/gri/plugin/exec_collector.rb
         | 
| 100 101 | 
             
            - lib/gri/plugin/juniper.rb
         | 
| 101 102 | 
             
            - lib/gri/plugin/netsnmp.rb
         | 
| 103 | 
            +
            - lib/gri/plugin/suppress_veth.rb
         | 
| 102 104 | 
             
            - lib/gri/plugin/ucdavis.rb
         | 
| 103 105 | 
             
            - lib/gri/plugin/writer_fluentd.rb
         | 
| 106 | 
            +
            - lib/gri/plugin/writer_influxdb.rb
         | 
| 104 107 | 
             
            - lib/gri/polling_unit.rb
         | 
| 105 108 | 
             
            - lib/gri/q.rb
         | 
| 106 109 | 
             
            - lib/gri/request.rb
         | 
| @@ -133,6 +136,7 @@ files: | |
| 133 136 | 
             
            - test/test_builtindefs.rb
         | 
| 134 137 | 
             
            - test/test_collector.rb
         | 
| 135 138 | 
             
            - test/test_config.rb
         | 
| 139 | 
            +
            - test/test_docker_collector.rb
         | 
| 136 140 | 
             
            - test/test_ds_list.rb
         | 
| 137 141 | 
             
            - test/test_exec_collector.rb
         | 
| 138 142 | 
             
            - test/test_format_helper.rb
         | 
| @@ -198,6 +202,7 @@ test_files: | |
| 198 202 | 
             
            - test/test_builtindefs.rb
         | 
| 199 203 | 
             
            - test/test_collector.rb
         | 
| 200 204 | 
             
            - test/test_config.rb
         | 
| 205 | 
            +
            - test/test_docker_collector.rb
         | 
| 201 206 | 
             
            - test/test_ds_list.rb
         | 
| 202 207 | 
             
            - test/test_exec_collector.rb
         | 
| 203 208 | 
             
            - test/test_format_helper.rb
         |