From 9de30afe731b36ea40ecf09f45f2f5c9d9d6fc72 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Wed, 25 Mar 2015 15:48:26 -0400 Subject: [PATCH] watchlog: be more resilient, log strange input and soldier on --- watchlog | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/watchlog b/watchlog index c5d0987..436c3c1 100755 --- a/watchlog +++ b/watchlog @@ -218,19 +218,24 @@ class Parser: def parseline(self, line): # sample stats line: # Mar 23 19:57:34 rl01-3-v1552 www_stats: stats {"hits":1,"pviews":0,"pview_avg_us":0,"boundary_epoch":1427140620.0,"unique_users":0,"pview_80th_us":0,"pview_50th_us":0,"ajax_hits":0} - parts = line.split(' ', 6) - hostname = parts[3] - stats = json.loads(parts[6]) - stats['hostname'] = hostname - # cast a few values to int - stats['boundary_epoch'] = int(stats['boundary_epoch']) - stats['pview_avg_us'] = int(stats['pview_avg_us']) - stats['pview_80th_us'] = int(stats['pview_80th_us']) - stats['pview_50th_us'] = int(stats['pview_50th_us']) - # workaround a buglet in compresslog v0.7 - # that gives us a list containing just one int for unique users :-/ - if isinstance(stats['unique_users'], list): - stats['unique_users'] = stats['unique_users'][0] + try: + parts = line.split(' ', 6) + hostname = parts[3] + stats = json.loads(parts[6]) + stats['hostname'] = hostname + # cast a few values to int + stats['boundary_epoch'] = int(stats['boundary_epoch']) + stats['pview_avg_us'] = int(stats['pview_avg_us']) + stats['pview_80th_us'] = int(stats['pview_80th_us']) + stats['pview_50th_us'] = int(stats['pview_50th_us']) + # workaround a buglet in compresslog v0.7 + # that gives us a list containing just one int for unique users :-/ + if isinstance(stats['unique_users'], list): + stats['unique_users'] = stats['unique_users'][0] + except: + e = sys.exc_info()[0] + sys.stderr.write('Caught exception %s while processing %s\n' % (e, line)) + self.cur.execute("""INSERT INTO logentries VALUES(:boundary_epoch, :hostname, :hits, :ajax_hits, :pviews, :pview_avg_us, :pview_50th_us, :pview_80th_us, :unique_users)""", stats) -- 2.11.4.GIT