Class: Logical::Naf::MetricSender
- Inherits:
-
Object
- Object
- Logical::Naf::MetricSender
- Defined in:
- app/models/logical/naf/metric_sender.rb
Instance Attribute Summary collapse
-
#last_sent_metrics ⇒ Object
Returns the value of attribute last_sent_metrics.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#metric_send_delay ⇒ Object
readonly
Returns the value of attribute metric_send_delay.
-
#statsd ⇒ Object
readonly
Returns the value of attribute statsd.
Instance Method Summary collapse
-
#initialize(metric_send_delay, machine) ⇒ MetricSender
constructor
A new instance of MetricSender.
-
#send_metrics ⇒ Object
Instance methods.
Constructor Details
#initialize(metric_send_delay, machine) ⇒ MetricSender
Returns a new instance of MetricSender.
13 14 15 16 17 18 |
# File 'app/models/logical/naf/metric_sender.rb', line 13 def initialize(metric_send_delay, machine) @metric_send_delay = metric_send_delay @statsd = Statsd.new @last_sent_metrics = nil @machine = machine end |
Instance Attribute Details
#last_sent_metrics ⇒ Object
Returns the value of attribute last_sent_metrics.
11 12 13 |
# File 'app/models/logical/naf/metric_sender.rb', line 11 def last_sent_metrics @last_sent_metrics end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
7 8 9 |
# File 'app/models/logical/naf/metric_sender.rb', line 7 def machine @machine end |
#metric_send_delay ⇒ Object (readonly)
Returns the value of attribute metric_send_delay.
7 8 9 |
# File 'app/models/logical/naf/metric_sender.rb', line 7 def metric_send_delay @metric_send_delay end |
#statsd ⇒ Object (readonly)
Returns the value of attribute statsd.
7 8 9 |
# File 'app/models/logical/naf/metric_sender.rb', line 7 def statsd @statsd end |
Instance Method Details
#send_metrics ⇒ Object
Instance methods
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 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/logical/naf/metric_sender.rb', line 22 def send_metrics if last_sent_metrics.nil? || (Time.zone.now - last_sent_metrics) > metric_send_delay.seconds running_job_count = ::Naf::HistoricalJob.where( "(started_at IS NOT NULL AND finished_at IS NULL AND " + "started_on_machine_id = ?)", machine.id).count + ::Naf::HistoricalJob.where( "(started_at IS NOT NULL AND finished_at > ? AND " + "started_on_machine_id = ?)", Time.zone.now - metric_send_delay.seconds, machine.id).count terminating_job_count = ::Naf::HistoricalJob.where( "(finished_at IS NULL AND request_to_terminate = true AND " + "started_on_machine_id = ?)", machine.id).count long_terminating_job_count = ::Naf::HistoricalJob.where( "(finished_at IS NULL AND request_to_terminate = true AND " + "updated_at < ? AND started_on_machine_id = ?)", Time.zone.now - 30.minutes, machine.id).count recent_errored_job_count = ::Naf::HistoricalJob.where( "(finished_at IS NOT NULL AND exit_status > 0 AND " + "finished_at > ? AND request_to_terminate = false " + "AND started_on_machine_id = ?)", Time.zone.now - metric_send_delay.seconds, machine.id).count statsd.gauge("naf.runner.alive", 1, tags: ::Naf.configuration.) statsd.gauge("naf.jobs.running", running_job_count, tags: ::Naf.configuration.) statsd.gauge("naf.jobs.terminating", terminating_job_count, tags: ::Naf.configuration.) statsd.gauge("naf.jobs.terminating-long", long_terminating_job_count, tags: ::Naf.configuration.) statsd.gauge("naf.jobs.recent-errored", recent_errored_job_count, tags: ::Naf.configuration.) last_sent_metrics = Time.zone.now end end |