Class: Rearview::StatsTask
- Inherits:
-
Object
- Object
- Rearview::StatsTask
- Includes:
- Celluloid, Logger
- Defined in:
- lib/rearview/stats_task.rb
Defined Under Namespace
Classes: StatsTaskError
Instance Attribute Summary collapse
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#statsd ⇒ Object
readonly
Returns the value of attribute statsd.
Instance Method Summary collapse
-
#initialize(delay = 120, start = true) ⇒ StatsTask
constructor
A new instance of StatsTask.
- #run ⇒ Object
- #schedule ⇒ Object
Methods included from Logger
Constructor Details
#initialize(delay = 120, start = true) ⇒ StatsTask
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rearview/stats_task.rb', line 9 def initialize(delay=120,start=true) @delay = delay @statsd = Rearview::Statsd.new # This number is not documented well. The batch size is actually the max # number of batch calls allowed, before the UDP message is sent. Anything # after this value is quietly dropped. However, keep in mind that the # safest max UDP message size is 512. # # So make sure that batch_size * 8bytes/per int < 512 @statsd.batch_size = 12 schedule if start end |
Instance Attribute Details
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
8 9 10 |
# File 'lib/rearview/stats_task.rb', line 8 def delay @delay end |
#statsd ⇒ Object (readonly)
Returns the value of attribute statsd.
8 9 10 |
# File 'lib/rearview/stats_task.rb', line 8 def statsd @statsd end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rearview/stats_task.rb', line 27 def run logger.debug "#{self} run" vm = Rearview::Vm.new @statsd.batch do |batch| batch.gauge('vm.total_memory',vm.total_memory.bytes_to_kilobytes) batch.gauge('vm.free_memory',vm.free_memory.bytes_to_kilobytes) batch.gauge('vm.max_memory',vm.max_memory.bytes_to_kilobytes) batch.gauge('vm.heap.committed',vm.heap.committed.bytes_to_kilobytes) batch.gauge('vm.heap.init',vm.heap.init.bytes_to_kilobytes) batch.gauge('vm.heap.max',vm.heap.max.bytes_to_kilobytes) batch.gauge('vm.heap.used',vm.heap.used.bytes_to_kilobytes) batch.gauge('vm.non_heap.committed',vm.non_heap.committed.bytes_to_kilobytes) batch.gauge('vm.non_heap.init',vm.non_heap.init.bytes_to_kilobytes) batch.gauge('vm.non_heap.max',vm.non_heap.max.bytes_to_kilobytes) batch.gauge('vm.non_heap.used',vm.non_heap.used.bytes_to_kilobytes) batch.gauge('monitor.total',( Rearview.config.monitor_enabled? ? Rearview.monitor_service.jobs.keys.count : 0 )) end rescue logger.error "#{self} run failed: #{$!}\n#{[email protected]("\n")}" ensure schedule end |
#schedule ⇒ Object
22 23 24 25 |
# File 'lib/rearview/stats_task.rb', line 22 def schedule logger.debug "#{self} schedule" @timer = after(@delay) { self.run } end |