Class: ScoutApm::Serializers::MetricsToJsonSerializer
- Inherits:
-
Object
- Object
- ScoutApm::Serializers::MetricsToJsonSerializer
- Defined in:
- lib/scout_apm/serializers/metrics_to_json_serializer.rb
Instance Attribute Summary collapse
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(metrics) ⇒ MetricsToJsonSerializer
constructor
A hash of meta => stat pairs.
-
#metric_as_json(meta, stat, child_metrics = {}) ⇒ Object
Children metrics is a hash of meta=>stat pairs.
- #transform_child_metrics(metrics) ⇒ Object
Constructor Details
#initialize(metrics) ⇒ MetricsToJsonSerializer
A hash of meta => stat pairs
7 8 9 |
# File 'lib/scout_apm/serializers/metrics_to_json_serializer.rb', line 7 def initialize(metrics) @metrics = metrics end |
Instance Attribute Details
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
4 5 6 |
# File 'lib/scout_apm/serializers/metrics_to_json_serializer.rb', line 4 def metrics @metrics end |
Instance Method Details
#as_json ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/scout_apm/serializers/metrics_to_json_serializer.rb', line 11 def as_json if metrics metrics.map{|, stat| metric_as_json(, stat) } else nil end end |
#metric_as_json(meta, stat, child_metrics = {}) ⇒ Object
Children metrics is a hash of meta=>stat pairs. Leave empty for no children. Supports only a single-level nesting, until we have redone metric classes, instead of Meta and Stats
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scout_apm/serializers/metrics_to_json_serializer.rb', line 22 def metric_as_json(, stat, child_metrics={}) { "bucket" => .type, "name" => .name, # No scope values needed here, since it's implied by the nesting. "count" => stat.call_count, "total_call_time" => stat.total_call_time, "total_exclusive_time" => stat.total_exclusive_time, "min_call_time" => stat.min_call_time, "max_call_time" => stat.max_call_time, # Pretty unsure how to synthesize histograms out of what we store now "total_histogram" => [ [stat.total_exclusive_time / stat.call_count, stat.call_count], ], "exclusive_histogram" => [ [stat.total_exclusive_time / stat.call_count, stat.call_count] ], "metrics" => transform_child_metrics(child_metrics), # Will later hold the exact SQL, or URL or whatever other detail # about this query is necessary "detail" => { :desc => .desc }.merge(.extra || {}), } end |
#transform_child_metrics(metrics) ⇒ Object
48 49 50 51 52 |
# File 'lib/scout_apm/serializers/metrics_to_json_serializer.rb', line 48 def transform_child_metrics(metrics) metrics.map do |, stat| metric_as_json(, stat) end end |