Class: BaseMetricsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/base_metrics_parser.rb

Instance Method Summary collapse

Instance Method Details

#clean_data(data_to_clean = []) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/fluent/plugin/base_metrics_parser.rb', line 20

def clean_data(data_to_clean = [])
  cleaned_data = []
  data_to_clean.each do |interim_data|
    cleaned_data << interim_data unless interim_data.include? '#'
  end
  cleaned_data
end

#emit_parsed_metrics(platform_metrics) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/base_metrics_parser.rb', line 36

def emit_parsed_metrics(platform_metrics)
  normalized_data = normalise_data(platform_metrics)
  cleaned_data = clean_data(normalized_data)
  hash_data_array = format_data(cleaned_data, @metric_prefix, '.')
  serialized_data = serialize_data(hash_data_array)
  serialized_data.each do |interim_data|
    @router.emit(@tag, Fluent::Engine.now, interim_data)
  end
end

#normalise_data(data_to_normalize = []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fluent/plugin/base_metrics_parser.rb', line 6

def normalise_data(data_to_normalize = [])
  normalized_data = []
  if data_to_normalize.length == 1
    data_to_normalize.each do |interim_data|
      normalized_data = interim_data.split(/\\n+|\\r+/).reject(&:empty?)
    end
  else
    data_to_normalize.each_line do |interim_data|
      normalized_data << interim_data.strip unless interim_data == "\n"
    end
  end
  normalized_data
end

#serialize_data(hashed_data_array = []) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/fluent/plugin/base_metrics_parser.rb', line 28

def serialize_data(hashed_data_array = [])
  serialised_data = []
  hashed_data_array.each do |interim_data|
    serialised_data << JSON.parse(interim_data.to_json)
  end
  serialised_data
end