Sha256: fc4766ce5c5fd7cb2f64af023502659bb3d383b89cd820766cf5e1aba4b98ca3

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 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 = {}
    cleaned_data.each do |interim_data|
      if interim_data =~ /{/ && interim_data =~ /}/
        metric_name, additional_dims, metric_val_and_time = interim_data.match(/(.*){(.*)}(.*)/i).captures
        additional_dim_name = ''
        if additional_dims =~ /,/
          additional_dims.split(/,/).map do |interim_dim_data|
            additional_dim_name += '_' unless additional_dim_name.nil? || additional_dim_name.empty?
            additional_dim_name += interim_dim_data.gsub(/"/, '').gsub(/=/, '_').gsub(/-/, '_') if interim_data =~ /=/
          end
        else
          additional_dim_name = additional_dims.gsub(/"/, '').gsub(/=/, '_').gsub(/-/, '_') if interim_data =~ /=/
        end
        if metric_val_and_time =~ / /
          hash_data["#{prefix}#{separator}#{metric_name}_#{additional_dim_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
        end
      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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