Browse Source

Show uptime in RPC getinfo result

master
Neil Booth 8 years ago
parent
commit
a019fde853
  1. 16
      lib/util.py
  2. 9
      server/controller.py

16
lib/util.py

@ -57,12 +57,20 @@ class cachedproperty(object):
return value return value
def formatted_time(t): def formatted_time(t, sep=' '):
'''Return a number of seconds as a string in days, hours, mins and '''Return a number of seconds as a string in days, hours, mins and
secs.''' maybe secs.'''
t = int(t) t = int(t)
return '{:d}d {:02d}h {:02d}m {:02d}s'.format( fmts = (('{:d}d', 86400), ('{:02d}h', 3600), ('{:02d}m', 60))
t // 86400, (t % 86400) // 3600, (t % 3600) // 60, t % 60) parts = []
for fmt, n in fmts:
val = t // n
if parts or val:
parts.append(fmt.format(val))
t %= n
if len(parts) < 3:
parts.append('{:02d}s'.format(t))
return sep.join(parts)
def deep_getsizeof(obj): def deep_getsizeof(obj):

9
server/controller.py

@ -464,6 +464,7 @@ class Controller(util.LoggedClass):
'sessions': self.session_count(), 'sessions': self.session_count(),
'subs': self.sub_count(), 'subs': self.sub_count(),
'txs_sent': self.txs_sent, 'txs_sent': self.txs_sent,
'uptime': util.formatted_time(time.time() - self.start_time),
} }
def sub_count(self): def sub_count(self):
@ -515,12 +516,6 @@ class Controller(util.LoggedClass):
'''A generator returning lines for a list of sessions. '''A generator returning lines for a list of sessions.
data is the return value of rpc_sessions().''' data is the return value of rpc_sessions().'''
def time_fmt(t):
t = int(t)
return ('{:3d}:{:02d}:{:02d}'
.format(t // 3600, (t % 3600) // 60, t % 60))
fmt = ('{:<6} {:<5} {:>17} {:>5} {:>5} ' fmt = ('{:<6} {:<5} {:>17} {:>5} {:>5} '
'{:>7} {:>7} {:>7} {:>7} {:>7} {:>9} {:>21}') '{:>7} {:>7} {:>7} {:>7} {:>7} {:>9} {:>21}')
yield fmt.format('ID', 'Flags', 'Client', 'Reqs', 'Txs', 'Subs', yield fmt.format('ID', 'Flags', 'Client', 'Reqs', 'Txs', 'Subs',
@ -535,7 +530,7 @@ class Controller(util.LoggedClass):
'{:,d}'.format(recv_size // 1024), '{:,d}'.format(recv_size // 1024),
'{:,d}'.format(send_count), '{:,d}'.format(send_count),
'{:,d}'.format(send_size // 1024), '{:,d}'.format(send_size // 1024),
time_fmt(time), peer) util.formatted_time(time, sep=''), peer)
def session_data(self, for_log): def session_data(self, for_log):
'''Returned to the RPC 'sessions' call.''' '''Returned to the RPC 'sessions' call.'''

Loading…
Cancel
Save