Module: LogStash::Api::Commands::Stats::PluginsStats

Defined in:
lib/logstash/api/commands/stats.rb

Class Method Summary collapse

Class Method Details

.decorate_vertex(vertex) ⇒ Hash{String=>Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a vertex, decorated with additional metadata if available. Does not mutate the passed ‘vertex` object.

Parameters:

  • vertex (Hash{String=>Object})

Returns:

  • (Hash{String=>Object})


171
172
173
174
175
176
177
178
179
180
# File 'lib/logstash/api/commands/stats.rb', line 171

def decorate_vertex(vertex)
  plugin_id = vertex["id"]&.to_s
  return vertex unless plugin_id && LogStash::PluginMetadata.exists?(plugin_id)

   = LogStash::PluginMetadata.for_plugin(plugin_id)
  cluster_uuid = &.get(:cluster_uuid)
  vertex = vertex.merge("cluster_uuid" => cluster_uuid) unless cluster_uuid.nil?

  vertex
end

.plugin_stats(stats, plugin_type) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'lib/logstash/api/commands/stats.rb', line 128

def plugin_stats(stats, plugin_type)
  # Turn the `plugins` stats hash into an array of [ {}, {}, ... ]
  # This is to produce an array of data points, one point for each
  # plugin instance.
  return [] unless stats[:plugins] && stats[:plugins].include?(plugin_type)
  stats[:plugins][plugin_type].collect do |id, data|
    { :id => id }.merge(data)
  end
end

.report(stats, extended_stats = nil, opts = {}) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/logstash/api/commands/stats.rb', line 138

def report(stats, extended_stats=nil, opts={})
  ret = {
    :events => stats[:events],
    :plugins => {
      :inputs => plugin_stats(stats, :inputs),
      :codecs => plugin_stats(stats, :codecs),
      :filters => plugin_stats(stats, :filters),
      :outputs => plugin_stats(stats, :outputs)
    },
    :reloads => stats[:reloads],
    :queue => stats[:queue]
  }
  ret[:dead_letter_queue] = stats[:dlq] if stats.include?(:dlq)

  # if extended_stats were provided, enrich the return value
  if extended_stats
    ret[:queue]    = extended_stats["queue"] if extended_stats.include?("queue")
    ret[:hash] = extended_stats["hash"]
    ret[:ephemeral_id] = extended_stats["ephemeral_id"]
    if opts[:vertices] && extended_stats.include?("vertices")
      ret[:vertices] = extended_stats["vertices"].map { |vertex| decorate_vertex(vertex) }
    end
  end

  ret
end