class Yabeda::Puma::Plugin::Statistics::Parser

Attributes

clustered[R]
data[R]

Public Class Methods

new(clustered:, data:) click to toggle source
# File lib/yabeda/puma/plugin/statistics/parser.rb, line 10
def initialize(clustered:, data:)
  @clustered = clustered
  @data = data
end

Public Instance Methods

call() click to toggle source
# File lib/yabeda/puma/plugin/statistics/parser.rb, line 15
def call
  [].tap { |result| parse(data, {}, result) }
end

Private Instance Methods

clustered_metric?(name) click to toggle source
# File lib/yabeda/puma/plugin/statistics/parser.rb, line 41
def clustered_metric?(name)
  clustered && Statistics::CLUSTERED_METRICS.include?(name.to_sym)
end
metric?(name) click to toggle source
# File lib/yabeda/puma/plugin/statistics/parser.rb, line 37
def metric?(name)
  Statistics::METRICS.include?(name.to_sym) || clustered_metric?(name)
end
parse(stats, labels, result) click to toggle source
# File lib/yabeda/puma/plugin/statistics/parser.rb, line 21
def parse(stats, labels, result)
  stats.each do |key, value|
    case key
    when 'worker_status'
      value.each { |s| parse(s, labels.merge(index: s['index']), result) }
    when 'last_status'
      parse(value, labels, result)
    else
      next unless metric?(key)

      l = clustered_metric?(key) ? labels : { index: 0 }.merge(labels)
      result << { name: key, value: value, labels: l }
    end
  end
end