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:
18 19 20 21 22 |
# File 'lib/nats/server/util.rb', line 18 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
79 80 81 82 83 84 85 |
# File 'lib/nats/server/util.rb', line 79 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:
2 3 4 5 6 |
# File 'lib/nats/server/util.rb', line 2 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:
12 13 14 15 16 |
# File 'lib/nats/server/util.rb', line 12 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:
30 31 32 |
# File 'lib/nats/server/util.rb', line 30 def log_error(e=$!) #:nodoc: debug e, e.backtrace end |
#num_cpu_cores ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nats/server/util.rb', line 53 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
45 46 47 48 49 50 51 |
# File 'lib/nats/server/util.rb', line 45 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:
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nats/server/util.rb', line 65 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:
8 9 10 |
# File 'lib/nats/server/util.rb', line 8 def syslog(args, priority) #:nodoc: Syslog::log(priority, '%s', PP::pp(args.compact, '', 120)) end |
#trace(*args) ⇒ Object
:nodoc:
24 25 26 27 28 |
# File 'lib/nats/server/util.rb', line 24 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
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nats/server/util.rb', line 34 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 |