Sha256: bd779b6f754fbcb1c1d50101d05fb69259843765641143104ca0ac5a6168a903

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true
require 'json'
require_relative 'base_metrics_parser'

class ElasticMetricsParser < BaseMetricsParser
  def initialize(metric_prefix, router, tag)
    @metric_prefix = metric_prefix
    @router = router
    @tag = tag
  end

  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] =~ /^\S*\.\S*$/ ? metric_val_and_time.strip.split[0].to_f : metric_val_and_time.strip.split[0].to_i
        hash_data_with_labels << hash_data_with_dim_fields
      else
        metric_name, value, = interim_data.split
        hash_data[prefix + separator + metric_name] =
            value =~ /^\S*\.\S*$/ ? value.to_f : value.to_i
      end
    end
    hash_data_array << hash_data
    (hash_data_array << hash_data_with_labels).flatten!
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-metrics-0.2.3 lib/fluent/plugin/elastic_metrics_parser.rb