Class: RequestQueueTime::AutoScalingMetrics::Reporter
- Inherits:
-
Object
- Object
- RequestQueueTime::AutoScalingMetrics::Reporter
- Includes:
- Singleton
- Defined in:
- lib/services/auto_scaling_metrics/reporter.rb
Constant Summary collapse
- DIMENSIONS =
[ {name: "service", value: ENV["DD_SERVICE"]}, {name: "environment", value: ENV["DD_ENV"]} ]
Instance Attribute Summary collapse
-
#collector ⇒ Object
Returns the value of attribute collector.
Class Method Summary collapse
Instance Method Summary collapse
- #add_metric(metric) ⇒ Object
- #start! {|_self| ... } ⇒ Object
- #started? ⇒ Boolean
- #stop! ⇒ Object
- #track_request_queue_time(time) ⇒ Object
Instance Attribute Details
#collector ⇒ Object
Returns the value of attribute collector.
19 20 21 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 19 def collector @collector end |
Class Method Details
.add_metric(metric) ⇒ Object
60 61 62 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 60 def self.add_metric(metric) instance.add_metric(metric) end |
.start ⇒ Object
21 22 23 24 25 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 21 def self.start(&) return false if instance.started? instance.start!(&) end |
.stop ⇒ Object
27 28 29 30 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 27 def self.stop return unless instance.started? instance.stop! end |
Instance Method Details
#add_metric(metric) ⇒ Object
64 65 66 67 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 64 def add_metric(metric) metric[:dimensions] = (metric[:dimensions] || []) + DIMENSIONS @buffer << metric end |
#start! {|_self| ... } ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 32 def start!(&block) Rails.logger.info "Starting AutoScalingMetrics::Reporter" @interval = 30 @buffer = Queue.new @buffer_size_limit = 1000 @cloudwatch = Aws::CloudWatch::Client.new @last_flush_time = Time.now @pid = Process.pid yield self if block start_flush_thread end |
#started? ⇒ Boolean
46 47 48 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 46 def started? @pid == Process.pid end |
#stop! ⇒ Object
50 51 52 53 54 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 50 def stop! @_thread&.terminate @_thread = nil @pid = nil end |
#track_request_queue_time(time) ⇒ Object
56 57 58 |
# File 'lib/services/auto_scaling_metrics/reporter.rb', line 56 def track_request_queue_time(time) add_metric(metric_name: "request_queue_time", value: time, unit: "Milliseconds", timestamp: Time.now) end |