chiark / gitweb /
tripe-admin manpage: Generate a command and message summary.
[tripe] / tripemon.in
index 6ba5de4e0f462bb986b80fd0d6b3f91fd6d483d9..0db0775247603f6c6f9d14010d65fb6fa90615dc 100644 (file)
@@ -7,6 +7,7 @@ import socket as S
 from sys import argv, exit, stdin, stdout, stderr
 import os as OS
 from os import environ
+import math as M
 import sets as SET
 import getopt as O
 import time as T
@@ -815,8 +816,15 @@ def xlate_time(t):
   """Translate a time in tripe's stats format to something a human might
   actually want to read."""
   if t == 'NEVER': return '(never)'
-  Y, M, D, h, m, s = map(int, rx_time.match(t).group(1, 2, 3, 4, 5, 6))
-  return '%04d:%02d:%02d %02d:%02d:%02d' % (Y, M, D, h, m, s)
+  YY, MM, DD, hh, mm, ss = map(int, rx_time.match(t).group(1, 2, 3, 4, 5, 6))
+  ago = T.time() - T.mktime((YY, MM, DD, hh, mm, ss, 0, 0, -1))
+  ago = M.floor(ago); unit = 's'
+  for n, u in [(60, 'min'), (60, 'hrs'), (24, 'days')]:
+    if ago < 2*n: break
+    ago /= n
+    unit = u
+  return '%04d:%02d:%02d %02d:%02d:%02d (%.1f %s ago)' % \
+         (YY, MM, DD, hh, mm, ss, ago, unit)
 def xlate_bytes(b):
   """Translate a number of bytes into something a human might want to read."""
   suff = 'B'
@@ -907,6 +915,8 @@ class PeerWindow (MyWindow):
   def ping(me):
     for ping in me.peer.ping, me.peer.eping:
       s = '%d/%d' % (ping.ngood, ping.n)
+      if ping.n:
+        s += ' (%.1f%%)' % (ping.ngood * 100.0/ping.n)
       if ping.ngood:
         s += '; %.2f ms (last %.1f ms)' % (ping.ttot/ping.ngood, ping.tlast);
       me.e[ping.cmd].set_text(s)