Class: LogStash::Instrument::Collector
- Inherits:
-
Object
- Object
- LogStash::Instrument::Collector
- 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
-
#agent ⇒ Object
Returns the value of attribute agent.
Instance Method Summary collapse
- #clear(keypath) ⇒ Object
- #get(namespaces_path, key, type) ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
-
#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.
-
#snapshot_metric ⇒ LogStash::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.
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize ⇒ Collector
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
#agent ⇒ Object
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
65 66 67 |
# File 'lib/logstash/instrument/collector.rb', line 65 def clear(keypath) @metric_store.prune(keypath) end |
#get(namespaces_path, key, type) ⇒ Object
50 51 52 53 54 |
# File 'lib/logstash/instrument/collector.rb', line 50 def get(namespaces_path, key, type) @metric_store.fetch_or_store(namespaces_path, key) do LogStash::Instrument::MetricType.create(type, namespaces_path, key) end 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 won’t stop processing events, theses errors are not considered fatal.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/logstash/instrument/collector.rb', line 34 def push(namespaces_path, key, type, *metric_type_params) begin get(namespaces_path, key, type).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_metric ⇒ LogStash::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.
61 62 63 |
# File 'lib/logstash/instrument/collector.rb', line 61 def snapshot_metric Snapshot.new(@metric_store.dup) end |