Sha256: 5c3739d3da070f14175789f1b447da72337111ecb3a87ac6460dca6cacd72af9

Contents?: true

Size: 1.7 KB

Versions: 17

Compression:

Stored size: 1.7 KB

Contents

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

class SplunkMetricsParser < 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 = []
    cleaned_data.each do |interim_data|
      hash_data_array << generate_hash_from_data(interim_data, prefix, separator)
    end
    hash_data_array
  end

  def generate_hash_from_data(data = '', prefix = '', separator = '')
    metrics_hash = {}
    if data =~ /{/ && data =~ /}/
      metric_name, additional_dims, metric_val_and_time = data.match(/(.*){(.*)}(.*)/i).captures
      if metric_val_and_time =~ / /
        metrics_hash['metric_name'] = prefix + separator + metric_name
        metrics_hash['value'] =
            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
        metrics_hash['time'] = metric_val_and_time.strip.split[1].to_i
        if additional_dims =~ /,/
          additional_dims.split(/,/).map do |interim_data|
            metrics_hash[interim_data.split(/=/)[0]] = interim_data.split(/=/)[1].gsub(/"/, '') if interim_data =~ /=/
          end
        end
      end
    else
      metrics_hash['metric_name'], metrics_hash['value'], metrics_hash['time'] = data.split
      metrics_hash['metric_name'] = prefix + separator + metrics_hash['metric_name']
      metrics_hash['value'] =
          metrics_hash['value'] =~ /^\S*\.\S*$/ ? metrics_hash['value'].to_f : metrics_hash['value'].to_i
      metrics_hash['time'] =  metrics_hash['time'].to_i
    end
    metrics_hash
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-metrics-0.2.13 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.3 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.2 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.1 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.11 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.10 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.9 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.8 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.7 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.6 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.5 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.4 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.3 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.2 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.1 lib/fluent/plugin/splunk_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.0 lib/fluent/plugin/splunk_metrics_parser.rb