Top Level Namespace
Defined Under Namespace
Modules: NATS, NATSD Classes: String, Sublist
Instance Method Summary collapse
-
#debug(*args) ⇒ Object
:nodoc:.
-
#dump_connection_state ⇒ Object
FIXME - Should probably be smarter when lots of connections.
-
#fast_uuid ⇒ Object
:nodoc:.
-
#log(*args) ⇒ Object
:nodoc:.
-
#log_error(e = $!) ⇒ Object
:nodoc:.
- #num_cpu_cores ⇒ Object
- #pretty_size(size, prec = 1) ⇒ Object
-
#shutdown ⇒ Object
:nodoc:.
-
#syslog(args, priority) ⇒ Object
:nodoc:.
-
#trace(*args) ⇒ Object
:nodoc:.
- #uptime_string(delta) ⇒ Object
Instance Method Details
#debug(*args) ⇒ Object
:nodoc:
19 20 21 22 23 |
# File 'lib/nats/server/util.rb', line 19 def debug(*args) #:nodoc: return unless NATSD::Server.debug_flag? return syslog(args, Syslog::LOG_INFO) if NATSD::Server.syslog log(*args) end |
#dump_connection_state ⇒ Object
FIXME - Should probably be smarter when lots of connections
80 81 82 83 84 85 86 |
# 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 |
#fast_uuid ⇒ Object
:nodoc:
3 4 5 6 7 |
# File 'lib/nats/server/util.rb', line 3 def fast_uuid #:nodoc: v = [rand(0x0010000),rand(0x0010000),rand(0x0010000), rand(0x0010000),rand(0x0010000),rand(0x1000000)] "%04x%04x%04x%04x%04x%06x" % v end |
#log(*args) ⇒ Object
:nodoc:
13 14 15 16 17 |
# File 'lib/nats/server/util.rb', line 13 def log(*args) #:nodoc: return syslog(args, Syslog::LOG_NOTICE) if NATSD::Server.syslog args.unshift(Time.now) if NATSD::Server.log_time PP::pp(args.compact, $stdout, 120) end |
#log_error(e = $!) ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/nats/server/util.rb', line 31 def log_error(e=$!) #:nodoc: debug e, e.backtrace end |
#num_cpu_cores ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
46 47 48 49 50 51 52 |
# 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 |
#shutdown ⇒ Object
:nodoc:
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nats/server/util.rb', line 66 def shutdown #:nodoc: puts log 'Server exiting..' NATSD::Server.close_syslog EM.stop if NATSD::Server.pid_file FileUtils.rm(NATSD::Server.pid_file) if File.exists? NATSD::Server.pid_file end exit end |
#syslog(args, priority) ⇒ Object
:nodoc:
9 10 11 |
# File 'lib/nats/server/util.rb', line 9 def syslog(args, priority) #:nodoc: Syslog::log(priority, '%s', PP::pp(args.compact, '', 120)) end |
#trace(*args) ⇒ Object
:nodoc:
25 26 27 28 29 |
# File 'lib/nats/server/util.rb', line 25 def trace(*args) #:nodoc: return unless NATSD::Server.trace_flag? return syslog(args, Syslog::LOG_DEBUG) if NATSD::Server.syslog log(*args) end |
#uptime_string(delta) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# 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 |