Class: TsdMetrics::JsonFormattingSink
- Inherits:
-
Object
- Object
- TsdMetrics::JsonFormattingSink
- Defined in:
- lib/tsd_metrics/json_formatting_sink.rb
Overview
Implements metricSink
Instance Method Summary collapse
-
#initialize(outputStream) ⇒ JsonFormattingSink
constructor
A new instance of JsonFormattingSink.
- #receive(tsdMetricEvent) ⇒ Object
- #record(tsdMetricEvent) ⇒ Object
Constructor Details
#initialize(outputStream) ⇒ JsonFormattingSink
Returns a new instance of JsonFormattingSink.
20 21 22 |
# File 'lib/tsd_metrics/json_formatting_sink.rb', line 20 def initialize(outputStream) @outputStream = outputStream end |
Instance Method Details
#receive(tsdMetricEvent) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tsd_metrics/json_formatting_sink.rb', line 23 def receive(tsdMetricEvent) hash = { time: Time.now.utc.iso8601(3), name: "aint.metrics", level: "info", data: { version: "2e", gauges: proxyValuesProperty(tsdMetricEvent.gauges), timers: proxyValuesProperty(tsdMetricEvent.timers), counters: proxyValuesProperty(tsdMetricEvent.counters), annotations: tsdMetricEvent.annotations } } haveMetrics = [:gauges, :timers, :counters].any? do |metricType| hash[:data][metricType].length > 0 end # The timestamp annotations are always present, but we're looking for # any further annotations. haveMetrics = true if hash[:data][:annotations].length > 2 return unless haveMetrics hash[:data][:annotations][:initTimestamp] = hash[:data][:annotations][:initTimestamp].utc.iso8601(3) hash[:data][:annotations][:finalTimestamp] = hash[:data][:annotations][:finalTimestamp].utc.iso8601(3) @outputStream.write(hash.to_json) end |
#record(tsdMetricEvent) ⇒ Object
50 51 52 |
# File 'lib/tsd_metrics/json_formatting_sink.rb', line 50 def record(tsdMetricEvent) receive(tsdMetricEvent) end |