log rtts; minor fixes

This commit is contained in:
2016-04-23 20:59:47 +02:00
parent ef5e41b23b
commit c192a6ea36
+23 -11
View File
@@ -34,6 +34,7 @@ SEND_PUSHOVER=True
DEBUG = 0
MAXRECV = 32767
MAXRTTS = 10
LOGFILE = "/home/andreas/public_html/messages/andreas"
PICKFILE = "/var/tmp/hbd.pick"
AEMAIL = ["andreas@wrede.ca"]
@@ -143,12 +144,11 @@ def oldmtodict(msg):
class Connection:
def __init__(self, name, cid, addr, port):
def __init__(self, name, cid, addr):
self.name = name
self.cid = cid
self.addr = addr
self.port = port
self.rtts = [0]
class Host:
@@ -271,9 +271,11 @@ class Host:
self.cver = 0
try:
a=host.connections
a=self.connections
a.append([])
except:
host.connections=[]
self.connections={}
self.connections={}
def getstate(self):
@@ -284,7 +286,12 @@ class Host:
if self.state in ["down", "overdue"]:
state = "<b>%s</b>" % self.state
elif self.state in ["up", "UP"]:
state = "%0.1f" % self.latency
state = ""
for x in self.connections.keys():
try:
state += " %5.1f" % self.connections[x].rtts[-1]
except:
state += " %5s" % self.connections[x].rtts[-1]
else:
state = "%s" % self.state
return state
@@ -486,15 +493,15 @@ def log(host, m, service=None):
def dnsupdatethread():
while True:
name, addr = dnsQ.get()
m = "%s changed address to %s" % (name, addr)
m = "changed address to %s" % (addr)
err = nsupdate(name, addr)
if err:
m += ", DNS failed: %s" % err
email("error: nsupdate failed", m)
m += ", DNS update failed: %s" % err
email("error: nsupdate failed", "%s: %s" % (name, m))
else:
m += ", DNS updated."
dnsQ.task_done()
log(m)
log(name, m)
#
#
@@ -536,6 +543,10 @@ def readsock(sock):
message = msg.get('msg', None)
boot = msg.get('boot', 0)
host.latency = now - msg.get('time', 0)
rtt = msg.get('rtt',"up")
conn.rtts.append(rtt)
if len(conn.rtts) > MAXRTTS:
del conn.rtts[0]
if boot:
log(name, "booted")
@@ -689,8 +700,9 @@ class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
(h, hosts[h].dispstate(), hosts[h].dispstats(), hosts[h].addr4, hosts[h].addr6, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hosts[h].statetime)), hosts[h].cver))
res.append("</table>")
le = max(40 - len(hosts), 3)
res.append("<h4>Log of Events</h4>")
for m in msgs[len(msgs)-30:]:
for m in msgs[len(msgs)-le:]:
res.append("%s<BR>" % m)
res.append("</body></html>")
return res