class Object
Public Instance Methods
dump_connection_state()
click to toggle source
FIXME - Should probably be smarter when lots of connections
# File lib/nats/server/util.rb, line 80 def dump_connection_state log "Dumping connection state on SIG_USR2" ObjectSpace.each_object(NATSD::Connection) do |c| log c.info unless c.closing? end log 'Connection Dump Complete' end
num_cpu_cores()
click to toggle source
# File lib/nats/server/util.rb, line 54 def num_cpu_cores if RUBY_PLATFORM =~ /linux/ return `cat /proc/cpuinfo | grep processor | wc -l`.to_i elsif RUBY_PLATFORM =~ /darwin/ `sysctl -n hw.ncpu`.strip.to_i elsif RUBY_PLATFORM =~ /freebsd|netbsd/ `sysctl hw.ncpu`.strip.to_i else return 1 end end
pretty_size(size, prec=1)
click to toggle source
# File lib/nats/server/util.rb, line 46 def pretty_size(size, prec=1) return 'NA' unless size return "#{size}B" if size < 1024 return sprintf("%.#{prec}fK", size/1024.0) if size < (1024*1024) return sprintf("%.#{prec}fM", size/(1024.0*1024.0)) if size < (1024*1024*1024) return sprintf("%.#{prec}fG", size/(1024.0*1024.0*1024.0)) end
uptime_string(delta)
click to toggle source
# File lib/nats/server/util.rb, line 35 def uptime_string(delta) num_seconds = delta.to_i days = num_seconds / (60 * 60 * 24); num_seconds -= days * (60 * 60 * 24); hours = num_seconds / (60 * 60); num_seconds -= hours * (60 * 60); minutes = num_seconds / 60; num_seconds -= minutes * 60; "#{days}d:#{hours}h:#{minutes}m:#{num_seconds}s" end