Class: HeimdallApm::PointsCollection
- Inherits:
-
Object
- Object
- HeimdallApm::PointsCollection
- Defined in:
- lib/heimdall_apm/points_collection.rb
Overview
Convert metrics hash from requests into an collection of points we want to track, but without aggregations and percentiles/std_dev calculations of same endpoints across multiples requests. These operations are deferred to InfluxDB, in favor of more granular data. This may change in the future if it proves non scalable.
Constant Summary collapse
- ROOT_METRICS =
Metrics we want to explicitely keep separated into measurements. Everything else will be label as Ruby.
['Sql', 'Elastic', 'Redis'].map do |key| downcased = key.downcase [key, ["#{downcased}_time", "#{downcased}_count"]] end.to_h
Instance Method Summary collapse
- #append(txn, metrics) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ PointsCollection
constructor
A new instance of PointsCollection.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ PointsCollection
Returns a new instance of PointsCollection.
18 19 20 |
# File 'lib/heimdall_apm/points_collection.rb', line 18 def initialize @points = [] end |
Instance Method Details
#append(txn, metrics) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/heimdall_apm/points_collection.rb', line 30 def append(txn, metrics) = txn.root_segment.stop_time series_name = txn.custom_series_name || (txn.web? ? 'app' : 'job') values = Hash.new { |h, k| h[k] = 0 } = txn. || {} [:endpoint] = txn.scope metrics.each do |, stat| if ROOT_METRICS.key?(.type) time_key, count_key = ROOT_METRICS[.type] values[time_key] += stat.total_exclusive_time values[count_key] += stat.call_count else values['ruby_time'] += stat.total_exclusive_time end values['total_time'] += stat.total_exclusive_time end # Segment time are in seconds, store them in milliseconds values.transform_values! { |v| v.is_a?(Integer) ? v : v * 1000 } @points << { series: series_name, timestamp: ( * 1000).to_i, tags: , values: values } end |
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/heimdall_apm/points_collection.rb', line 22 def empty? @points.empty? end |
#to_a ⇒ Object
26 27 28 |
# File 'lib/heimdall_apm/points_collection.rb', line 26 def to_a @points end |