Sha256: 48cb81c29a05bbce5fdb1c38b5a45b8e71031f0959ac27d05b51a6ed7461682e
Contents?: true
Size: 1.27 KB
Versions: 5
Compression:
Stored size: 1.27 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].to_f hash_data_with_labels << hash_data_with_dim_fields else metric_name, value, = interim_data.split hash_data[prefix + separator + metric_name] = value.to_f end end hash_data_array << hash_data (hash_data_array << hash_data_with_labels).flatten! end end
Version data entries
5 entries across 5 versions & 1 rubygems