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.
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
20 21 22 23 |
# File 'lib/logstash/instrument/collector.rb', line 20 def initialize @metric_store = MetricStore.new @agent = nil end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
18 19 20 |
# File 'lib/logstash/instrument/collector.rb', line 18 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 |
#get(namespaces_path, key, type) ⇒ Object
48 49 50 51 52 |
# File 'lib/logstash/instrument/collector.rb', line 48 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/logstash/instrument/collector.rb', line 32 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.
59 60 61 |
# File 'lib/logstash/instrument/collector.rb', line 59 def snapshot_metric Snapshot.new(@metric_store.dup) end |