Class: Bipbip::Plugin::LogParser
- Inherits:
-
Bipbip::Plugin
- Object
- Bipbip::Plugin
- Bipbip::Plugin::LogParser
- Defined in:
- lib/bipbip/plugin/log_parser.rb
Instance Attribute Summary
Attributes inherited from Bipbip::Plugin
#config, #frequency, #metric_group, #name, #tags
Instance Method Summary collapse
Methods inherited from Bipbip::Plugin
factory, factory_from_plugin, #initialize, #metrics_names, #run, #source_identifier
Methods included from InterruptibleSleep
#interrupt_sleep, #interruptible_sleep
Constructor Details
This class inherits a constructor from Bipbip::Plugin
Instance Method Details
#metrics_schema ⇒ Object
5 6 7 8 9 |
# File 'lib/bipbip/plugin/log_parser.rb', line 5 def metrics_schema config['matchers'].map do |matcher| { name: matcher['name'], type: 'gauge', unit: 'Boolean' } end end |
#monitor ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bipbip/plugin/log_parser.rb', line 11 def monitor begin io = IO.select([notifier.to_io], [], [], 0) rescue Errno::EBADF => e log(Logger::WARN, 'Selecting from inotify IO gives EBADF, resetting notifier') reset_notifier end unless io.nil? n = notifier begin n.process rescue NoMethodError => e # Ignore errors from closed notifier - see https://github.com/nex3/rb-inotify/issues/41 raise e unless n.watchers.empty? end end lines = @lines.entries @lines.clear Hash[ config['matchers'].map do |matcher| name = matcher['name'] regexp = Regexp.new(matcher['regexp']) value = lines.count { |line| !line.match(regexp).nil? } [name, value] end ] end |