Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 56 lines (43 sloc) 1.182 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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
require File.join(File.dirname(__FILE__),'..','lib','health_manager')

require 'pp'

@tiers = {}

compact = false

def showem
  puts "DEA Tenancy. Tier count: #{@tiers.size} #{Time.now}"
  @tiers.keys.sort.each do |tier|
    deas = @tiers[tier]
    puts "Tier: #{tier}, Size: #{deas.size} deas"
    deas.keys.sort.each { |dea|
      droplets = deas[dea]
      puts " #{dea}"
      puts " #{droplets.inspect}"
    }
  end
end

def showem_and_stop
  showem
  NATS.stop
end

['INT','SIGTERM'].each {|sig| trap(sig) { NATS.stop }}

NATS.start :uri => ENV['NATS_URI'] do

  NATS.subscribe('dea.heartbeat') do |json|

    msg = Yajl::Parser.parse(json)

    dea = msg['dea']
    tier = msg['tier'] || "DEFAULT"
    deas = @tiers[tier] ||= {}
    enough = deas.has_key? dea

    if compact
      deas[dea] = msg['droplets'].inject(Hash.new(0)) do |h,d|
        h[d['state']] += 1
        h
      end
    else
      deas[dea] = msg['droplets'].map { |d|
        #puts d
        klass_letter = d['droplet'].class.to_s[0].downcase
        "#{d['state'][0]}:#{d['droplet']}#{klass_letter}:#{d['index']}@#{d['cc_partition']}"
      }
    end


    showem_and_stop if enough
  end
end
Something went wrong with that request. Please try again.