Class: ElasticMetricsParser

Inherits:
BaseMetricsParser show all
Defined in:
lib/fluent/plugin/elastic_metrics_parser.rb

Instance Method Summary collapse

Methods inherited from BaseMetricsParser

#clean_data, #emit_parsed_metrics, #normalise_data, #serialize_data

Constructor Details

#initialize(metric_prefix, router, tag) ⇒ ElasticMetricsParser

Returns a new instance of ElasticMetricsParser.



6
7
8
9
10
# File 'lib/fluent/plugin/elastic_metrics_parser.rb', line 6

def initialize(metric_prefix, router, tag)
  @metric_prefix = metric_prefix
  @router = router
  @tag = tag
end

Instance Method Details

#format_data(cleaned_data = [], prefix = '', separator = '') ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fluent/plugin/elastic_metrics_parser.rb', line 12

def format_data(cleaned_data = [], prefix = '', separator = '')
  hash_data_array = []
  hash_data = {}
  hash_data_with_labels = []
  cleaned_data.each do |interim_data|
    if interim_data =~ /{/ && interim_data =~ /}/
      hash_data_with_dim_fields = {}
      metric_name, additional_dims, metric_val_and_time = interim_data.match(/(.*){(.*)}(.*)/i).captures
      additional_dims.split(/,/).map do |interim_dim_data|
        hash_data_with_dim_fields[prefix + separator + "label" + separator + interim_dim_data.split(/=/)[0]] = interim_dim_data.split(/=/)[1].gsub(/"/, '') if interim_dim_data =~ /=/
      end
      hash_data_with_dim_fields[prefix + separator + metric_name] = metric_val_and_time.strip.split[0].to_f
      hash_data_with_labels << hash_data_with_dim_fields
    else
      metric_name, value, = interim_data.split
      hash_data[prefix + separator + metric_name] = value.to_f
    end
  end
  hash_data_array << hash_data
  (hash_data_array << hash_data_with_labels).flatten!
end