From 2a4be86179d695506a622cacd3cf7f29de13159b Mon Sep 17 00:00:00 2001 From: andreas Date: Wed, 20 Jul 2005 14:03:46 +0000 Subject: [PATCH] cleanup --- hbc | 5 +++-- hbd | 12 +++++++++--- hbmsg | 15 --------------- 3 files changed, 12 insertions(+), 20 deletions(-) delete mode 100755 hbmsg diff --git a/hbc b/hbc index 9532746..0ded65a 100755 --- a/hbc +++ b/hbc @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: hbc,v 1.3 2005/07/19 20:31:05 andreas Exp $ +# $Id: hbc,v 1.4 2005/07/20 14:03:46 andreas Exp $ import sys, time, socket, os, signal, getopt, string PORT=50003 @@ -124,6 +124,7 @@ if not msgonly: if len(msgboot) > 0: msgboot.append("name=%s" % iam) + msgboot.append("time=%s" % time.time()) msg=string.join(msgboot,";") while 1: fail=0 @@ -160,7 +161,6 @@ if daemon: os.umask(0) -msg="interval=%s;name=%s" % (interval, iam) up=1 signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGHUP, handler) @@ -172,6 +172,7 @@ while up: break for hb_host in hb_hosts: try: + msg="interval=%s;name=%s;time=%s" % (interval, iam, time.time()) if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port) sock.sendto(msg, (hb_host, hb_port)) except: diff --git a/hbd b/hbd index dc31ff6..3def04a 100755 --- a/hbd +++ b/hbd @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: hbd,v 1.2 2005/07/19 20:31:05 andreas Exp $ +# $Id: hbd,v 1.3 2005/07/20 14:03:46 andreas Exp $ # Wait for heartbeat messages and act on them (or their absence) # import time, os, string, sys, socket, curses, atexit, select, SocketServer, getopt @@ -269,6 +269,7 @@ def readsock(): name="unknown" msg=None interval=0 + deltaT=0.0 for pair in pairs: l=string.split(pair,"=") key=l[0] @@ -288,10 +289,15 @@ def readsock(): msg=val elif key == 'service': service=val + elif key == 'time': + try: + deltaT=now-float(val) + except: + pass if boot: - log("%s booted" % name) + log("%s booted, deltaT %0.2g sec" % (name, deltaT)) if msg: - log("%s msg: %s" % (name, msg),service=service) + log("%s %0.2g msg: %s" % (name, deltaT, msg),service=service) fromaddr(name, addr[0], boot, interval) if shutdown: log("%s shutdown" % name) diff --git a/hbmsg b/hbmsg deleted file mode 100755 index 15d5e99..0000000 --- a/hbmsg +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python -# $Id: hbmsg,v 1.1 2005/07/14 19:28:59 andreas Exp $ -import time, socket - -ADDR="204.29.161.33" -#ADDR="10.99.1.4" -PORT=50003 -SERVICE="service" - -iam=socket.gethostname() -sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) -msgboot="msg=This is a test;service=%s;name=%s" % (SERVICE, iam) -sock.sendto(msgboot, (ADDR, PORT)) -time.sleep(1) -sock.close()