watchd: add totals statistics

This commit is contained in:
rofl0r
2019-01-11 00:43:16 +00:00
parent 4c6a83373f
commit 7d59404d31

View File

@@ -15,6 +15,11 @@ config = Config()
_run_standalone = False
cached_dns = dict()
def try_div(a, b):
if b != 0: return a/float(b)
return 0
class WorkerJob():
def __init__(self, proxy, proto, failcount, success_count, total_duration):
self.proxy = proxy
@@ -164,9 +169,6 @@ class WorkerThread():
self.thread = threading.Thread(target=self.workloop)
self.thread.start()
def workloop(self):
def try_div(a, b):
if b != 0: return a/float(b)
return 0
success_count = 0
job_count = 0
duration_total = 0
@@ -214,6 +216,8 @@ class Proxywatchd():
def finish(self):
if not self.in_background: self._cleanup()
while not self.stopped.is_set(): time.sleep(0.1)
success_rate = try_div(self.totals['success'], self.totals['submitted']) * 100
_log("total results: %d/%d (%.2f%%)"%(self.totals['success'], self.totals['submitted'], success_rate), "watchd")
def _prep_db(self):
self.mysqlite = mysqlite.mysqlite(config.watchd.database, str)
@@ -237,6 +241,10 @@ class Proxywatchd():
self.submit_after = config.watchd.submit_after # number of collected jobs before writing db
self.jobs = []
self.collected = []
self.totals = {
'submitted':0,
'success':0,
}
def prepare_jobs(self):
self._prep_db()
@@ -284,6 +292,8 @@ class Proxywatchd():
self.mysqlite.commit()
self._close_db()
self.collected = []
self.totals['submitted'] += len(args)
self.totals['success'] += sc
return ret
def start(self):