watchd: add totals statistics
This commit is contained in:
@@ -15,6 +15,11 @@ config = Config()
|
|||||||
_run_standalone = False
|
_run_standalone = False
|
||||||
cached_dns = dict()
|
cached_dns = dict()
|
||||||
|
|
||||||
|
def try_div(a, b):
|
||||||
|
if b != 0: return a/float(b)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class WorkerJob():
|
class WorkerJob():
|
||||||
def __init__(self, proxy, proto, failcount, success_count, total_duration):
|
def __init__(self, proxy, proto, failcount, success_count, total_duration):
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
@@ -164,9 +169,6 @@ class WorkerThread():
|
|||||||
self.thread = threading.Thread(target=self.workloop)
|
self.thread = threading.Thread(target=self.workloop)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
def workloop(self):
|
def workloop(self):
|
||||||
def try_div(a, b):
|
|
||||||
if b != 0: return a/float(b)
|
|
||||||
return 0
|
|
||||||
success_count = 0
|
success_count = 0
|
||||||
job_count = 0
|
job_count = 0
|
||||||
duration_total = 0
|
duration_total = 0
|
||||||
@@ -214,6 +216,8 @@ class Proxywatchd():
|
|||||||
def finish(self):
|
def finish(self):
|
||||||
if not self.in_background: self._cleanup()
|
if not self.in_background: self._cleanup()
|
||||||
while not self.stopped.is_set(): time.sleep(0.1)
|
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):
|
def _prep_db(self):
|
||||||
self.mysqlite = mysqlite.mysqlite(config.watchd.database, str)
|
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.submit_after = config.watchd.submit_after # number of collected jobs before writing db
|
||||||
self.jobs = []
|
self.jobs = []
|
||||||
self.collected = []
|
self.collected = []
|
||||||
|
self.totals = {
|
||||||
|
'submitted':0,
|
||||||
|
'success':0,
|
||||||
|
}
|
||||||
|
|
||||||
def prepare_jobs(self):
|
def prepare_jobs(self):
|
||||||
self._prep_db()
|
self._prep_db()
|
||||||
@@ -284,6 +292,8 @@ class Proxywatchd():
|
|||||||
self.mysqlite.commit()
|
self.mysqlite.commit()
|
||||||
self._close_db()
|
self._close_db()
|
||||||
self.collected = []
|
self.collected = []
|
||||||
|
self.totals['submitted'] += len(args)
|
||||||
|
self.totals['success'] += sc
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user