#!/usr/bin/env python
import os, sys
LOGS = "/home/salvus/logs"
def count(f, s, lines, exclude):
fname = os.path.join(LOGS, f)
if not os.path.exists(fname):
return -1
if lines:
c = "tail -n %s %s"%(lines, fname)
else:
c = "cat %s"%fname
c += " | grep '%s' "%s
if exclude:
c += " | grep -v '%s'"%exclude
c += "| wc -l"
n = int(os.popen(c).read())
return n
def check(num):
strings = [('concurrent_warn',num,''),('is taking over',num,''), ('RqlRuntimeError',num,'Connection is closed'), ('There may have been an error creating your account',num,''), ("here was an error signing you in",num,'')]
for f in sorted(os.listdir(LOGS)):
if f.startswith('hub') and f.endswith('.log'):
for s,lines,exclude in strings:
i = count(f, s, lines, exclude)
if i > 0:
print 'last %s:'%lines, f, i, "'%s'"%s
if len(sys.argv) == 1:
sys.argv.append('50000')
sys.argv.append('5000')
sys.argv.append('500')
for num in sys.argv[1:]:
check(int(num))