Module: Munin::Parser
- Included in:
- Connection, Node
- Defined in:
- lib/munin-ruby/parser.rb
Instance Method Summary collapse
-
#parse_config(data) ⇒ Object
Parse ‘config’ request.
-
#parse_config_args(args) ⇒ Object
Parse configuration arguments.
-
#parse_error(lines) ⇒ Object
Detect error from output.
-
#parse_fetch(data) ⇒ Object
Parse ‘fetch’ request.
-
#parse_version(line) ⇒ Object
Parse a version request.
-
#process_data(lines) ⇒ Object
Process response.
Instance Method Details
#parse_config(data) ⇒ Object
Parse ‘config’ request
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/munin-ruby/parser.rb', line 27 def parse_config(data) config = {'graph' => {}, 'metrics' => {}} data.each do |l| if l =~ /^graph_/ key_name, value = l.scan(/^graph_([\w]+)\s(.*)/).flatten config['graph'][key_name] = value # according to http://munin-monitoring.org/wiki/notes_on_datasource_names elsif l =~ /^[a-zA-Z_][a-zA-Z\d_]*\./ # according to http://munin-monitoring.org/wiki/fieldnames the second one # can only be [a-z] matches = l.scan(/^([a-zA-Z_][a-zA-Z\d_]*)\.([a-z]+)\s(.*)/).flatten config['metrics'][matches[0]] ||= {} config['metrics'][matches[0]][matches[1]] = matches[2] end end # Now, lets process the args hash if config['graph'].key?('args') config['graph']['args'] = parse_config_args(config['graph']['args']) end config end |
#parse_config_args(args) ⇒ Object
Parse configuration arguments
70 71 72 73 74 75 76 |
# File 'lib/munin-ruby/parser.rb', line 70 def parse_config_args(args) result = {} args.scan(/--?([a-z\-\_]+)\s([\d]+)\s?/).each do |arg| result[arg.first] = arg.last end {'raw' => args, 'parsed' => result} end |
#parse_error(lines) ⇒ Object
Detect error from output
59 60 61 62 63 64 65 66 |
# File 'lib/munin-ruby/parser.rb', line 59 def parse_error(lines) if lines.size == 1 case lines.first when '# Unknown service' then raise UnknownService when '# Bad exit' then raise BadExit end end end |
#parse_fetch(data) ⇒ Object
Parse ‘fetch’ request
53 54 55 |
# File 'lib/munin-ruby/parser.rb', line 53 def parse_fetch(data) process_data(data) end |
#parse_version(line) ⇒ Object
Parse a version request
5 6 7 8 9 10 11 |
# File 'lib/munin-ruby/parser.rb', line 5 def parse_version(line) if line =~ /^munins node on/ line.split.last else raise Munin::InvalidResponse, "Invalid version response" end end |
#process_data(lines) ⇒ Object
Process response
15 16 17 18 19 20 21 22 23 |
# File 'lib/munin-ruby/parser.rb', line 15 def process_data(lines) data = {} lines.each do |line| line = line.split key = line.first.split('.value').first data[key] = line.last end data end |