Class: LogStash::Instrument::Collector

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/instrument/collector.rb

Overview

The Collector is the single point of reference for all the metrics collection inside logstash, the metrics library will make direct calls to this class.

Constant Summary collapse

SNAPSHOT_ROTATION_TIME_SECS =

seconds

1
SNAPSHOT_ROTATION_TIMEOUT_INTERVAL_SECS =

seconds

10 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Loggable

included, #logger, #slow_logger

Constructor Details

#initializeCollector

Returns a new instance of Collector.



22
23
24
25
# File 'lib/logstash/instrument/collector.rb', line 22

def initialize
  @metric_store = MetricStore.new
  @agent = nil
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



20
21
22
# File 'lib/logstash/instrument/collector.rb', line 20

def agent
  @agent
end

Instance Method Details

#clear(keypath) ⇒ Object



63
64
65
# File 'lib/logstash/instrument/collector.rb', line 63

def clear(keypath)
  @metric_store.prune(keypath)
end

#push(namespaces_path, key, type, *metric_type_params) ⇒ Object

The metric library will call this unique interface its the job of the collector to update the store with new metric of update the metric

If there is a problem with the key or the type of metric we will record an error but we wont stop processing events, theses errors are not considered fatal.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/logstash/instrument/collector.rb', line 34

def push(namespaces_path, key, type, *metric_type_params)
  begin
    metric = @metric_store.fetch_or_store(namespaces_path, key) do
      LogStash::Instrument::MetricType.create(type, namespaces_path, key)
    end

    metric.execute(*metric_type_params)
  rescue MetricStore::NamespacesExpectedError => e
    logger.error("Collector: Cannot record metric", :exception => e)
  rescue NameError => e
    logger.error("Collector: Cannot create concrete class for this metric type",
                 :type => type,
                 :namespaces_path => namespaces_path,
                 :key => key,
                 :metrics_params => metric_type_params,
                 :exception => e,
                 :stacktrace => e.backtrace)
  end
end

#snapshot_metricLogStash::Instrument::MetricStore

Snapshot the current Metric Store and return it immediately, This is useful if you want to get access to the current metric store without waiting for a periodic call.



59
60
61
# File 'lib/logstash/instrument/collector.rb', line 59

def snapshot_metric
  Snapshot.new(@metric_store.dup)
end