Sha256: cea42cea15319ca3ba20ba76291823a740a9955c30a6d9c146e9f1ae2a9354d9

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

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

class NewRelicMetricsParser < 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 = []
    data_hash = {}
    data_array = []
    cleaned_data.each do |interim_data|
      metrics_hash = {}
      if interim_data =~ /{/ && interim_data =~ /}/
        attributes = {}
        metric_name, additional_dims, metric_val_and_time = interim_data.match(/(.*){(.*)}(.*)/i).captures
        additional_dims.split("\",").each do |interim_data|
          pair_data = interim_data.gsub("\"", "").gsub("{", "").gsub("}", "")
          interim_data_value = pair_data.split("=", 2)[1]
          interim_data_key = pair_data.split("=", 2)[0]
          attributes[interim_data_key] = interim_data_value
        end
        if metric_val_and_time =~ / /
          metrics_hash['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['timestamp'] = metric_val_and_time.strip.split[1].to_i
          metrics_hash['attributes'] = attributes
        end
      else
        metrics_hash['name'], metrics_hash['value'], metrics_hash['timestamp'] = interim_data.split
        metrics_hash['name'] = prefix + separator + metrics_hash['name']
        metrics_hash['value'] =
            metrics_hash['value'] =~ /^\S*\.\S*$/ ? metrics_hash['value'].to_f : metrics_hash['value'].to_i
        metrics_hash['timestamp'] = metrics_hash['timestamp'].to_i
      end
      data_array << metrics_hash
    end
    data_hash["metrics"] = data_array
    hash_data_array.push(data_hash)
    hash_data_array
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-metrics-0.2.13 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.3 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.2 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12.1 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.12 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.11 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.10 lib/fluent/plugin/newrelic_metrics_parser.rb
fluent-plugin-jfrog-metrics-0.2.9 lib/fluent/plugin/newrelic_metrics_parser.rb