Module: TingYun::Agent::Collector::StatsEngine::MetricStats
- Included in:
- TingYun::Agent::Collector::StatsEngine
- Defined in:
- lib/ting_yun/agent/collector/stats_engine/metric_stats.rb
Constant Summary collapse
- SCOPE_PLACEHOLDER =
Handles methods related to actual Metric collection
'__SCOPE__'.freeze
Instance Method Summary collapse
- #coerce_to_metric_spec_array(metric_names_or_specs, scope) ⇒ Object
- #harvest! ⇒ Object
- #harvest_base_quantile_hash! ⇒ Object
-
#merge!(other_stats_hash) ⇒ Object
merge data from previous harvests into this stats engine.
- #merge_transaction_metrics!(txn_metrics, scope) ⇒ Object
- #record_scoped_and_unscoped_metrics(state, scoped_metric, summary_metrics = nil, value = nil, aux = nil, &blk) ⇒ Object
- #record_unscoped_metrics(state, metric_names, value = nil, aux = nil, &blk) ⇒ Object
- #reset! ⇒ Object
- #reset_stats ⇒ Object deprecated Deprecated.
-
#tl_record_scoped_and_unscoped_metrics(scoped_metric, summary_metrics = nil, value = nil, aux = nil, &blk) ⇒ Object
private
Like tl_record_unscoped_metrics, but records a scoped metric as well.
- #tl_record_unscoped_metrics(metric_names, value = nil, aux = nil, &blk) ⇒ Object
-
#to_h ⇒ Object
For use by test code only.
Instance Method Details
#coerce_to_metric_spec_array(metric_names_or_specs, scope) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 113 def coerce_to_metric_spec_array(metric_names_or_specs, scope) specs = [] Array(metric_names_or_specs).map do |name_or_spec| case name_or_spec when String specs << TingYun::Metrics::MetricSpec.new(name_or_spec) specs << TingYun::Metrics::MetricSpec.new(name_or_spec, scope) if scope when TingYun::Metrics::MetricSpec specs << name_or_spec end end specs end |
#harvest! ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 134 def harvest! snapshot = nil with_stats_lock do snapshot = @stats_hash snapshot.harvested_at = Time.now @stats_hash = StatsHash.new end snapshot end |
#harvest_base_quantile_hash! ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 144 def harvest_base_quantile_hash! snapshot = nil with_stats_lock do snapshot = @base_quantile_hash @base_quantile_hash = BaseQuantileHash.new end snapshot end |
#merge!(other_stats_hash) ⇒ Object
merge data from previous harvests into this stats engine
159 160 161 162 163 164 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 159 def merge!(other_stats_hash) with_stats_lock do @stats_hash.merge!(other_stats_hash) @stats_hash end end |
#merge_transaction_metrics!(txn_metrics, scope) ⇒ Object
171 172 173 174 175 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 171 def merge_transaction_metrics!(txn_metrics, scope) with_stats_lock do @stats_hash.merge_transaction_metrics!(txn_metrics, scope) end end |
#record_scoped_and_unscoped_metrics(state, scoped_metric, summary_metrics = nil, value = nil, aux = nil, &blk) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 93 def record_scoped_and_unscoped_metrics(state, scoped_metric, summary_metrics=nil, value=nil, aux=nil ,&blk) txn = state.current_transaction if txn txn.metrics.record_scoped(scoped_metric, value, aux, &blk) txn.metrics.record_unscoped(scoped_metric, value, aux, &blk) if summary_metrics txn.metrics.record_unscoped(summary_metrics, value, aux, &blk) end else specs = coerce_to_metric_spec_array(scoped_metric, nil) if summary_metrics specs.concat(coerce_to_metric_spec_array(summary_metrics, nil)) end with_stats_lock do @stats_hash.record(specs, value, aux, &blk) end end end |
#record_unscoped_metrics(state, metric_names, value = nil, aux = nil, &blk) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 56 def record_unscoped_metrics(state, metric_names, value=nil, aux=nil, &blk) txn = state.current_transaction if txn txn.metrics.record_unscoped(metric_names, value, aux, &blk) else specs = coerce_to_metric_spec_array(metric_names, nil) with_stats_lock do @stats_hash.record(specs, value, aux, &blk) end end end |
#reset! ⇒ Object
127 128 129 130 131 132 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 127 def reset! with_stats_lock do @stats_hash = StatsHash.new @base_quantile_hash = BaseQuantileHash.new end end |
#reset_stats ⇒ Object
Renamed to reset!, here for backwards compatibility with 3rd-party gems (though this really isn’t part of the public API).
156 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 156 def reset_stats; reset!; end |
#tl_record_scoped_and_unscoped_metrics(scoped_metric, summary_metrics = nil, value = nil, aux = nil, &blk) ⇒ 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.
Like tl_record_unscoped_metrics, but records a scoped metric as well.
This is an internal method, subject to change at any time. Client apps and gems should use the public API (TingYun::Agent.record_metric) instead.
The given scoped_metric will be recoded as both a scoped and an unscoped metric. The summary_metrics will be recorded as unscoped metrics only.
If called during a transaction, all metrics will be attached to the Transaction, and not merged into the global set of metrics until the end of the transaction.
If called outside of a transaction, only the unscoped metrics will be recorded, directly into the global set of metrics (under a lock).
88 89 90 91 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 88 def tl_record_scoped_and_unscoped_metrics(scoped_metric, summary_metrics=nil, value=nil, aux=nil, &blk) state = TingYun::Agent::TransactionState.tl_get record_scoped_and_unscoped_metrics(state, scoped_metric, summary_metrics, value, aux, &blk) end |
#tl_record_unscoped_metrics(metric_names, value = nil, aux = nil, &blk) ⇒ Object
51 52 53 54 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 51 def tl_record_unscoped_metrics(metric_names, value=nil, aux=nil, &blk) state = TingYun::Agent::TransactionState.tl_get record_unscoped_metrics(state, metric_names, value, aux, &blk) end |
#to_h ⇒ Object
For use by test code only.
167 168 169 |
# File 'lib/ting_yun/agent/collector/stats_engine/metric_stats.rb', line 167 def to_h with_stats_lock { @stats_hash.to_h } end |