Sha256: 827f328d3c1d19c7a4829ab98614085eacfd2639f6bf5b4f5f627886157c9f6b

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 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 + 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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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