watchd: collect stats
This commit is contained in:
@@ -117,18 +117,37 @@ 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
|
||||||
|
job_count = 0
|
||||||
|
duration_total = 0
|
||||||
|
duration_success_total = 0
|
||||||
while True:
|
while True:
|
||||||
if len(self.workqueue):
|
if len(self.workqueue):
|
||||||
job = self.workqueue.pop()
|
job = self.workqueue.pop()
|
||||||
|
nao = time.time()
|
||||||
job.run()
|
job.run()
|
||||||
|
spent = time.time() - nao
|
||||||
|
if job.failcount == 0:
|
||||||
|
duration_success_total += spent
|
||||||
|
success_count += 1
|
||||||
|
job_count += 1
|
||||||
|
duration_total += spent
|
||||||
self.workdone.append(job)
|
self.workdone.append(job)
|
||||||
elif not self.thread:
|
elif not self.thread:
|
||||||
break
|
break
|
||||||
if self.done.is_set(): break
|
if self.done.is_set(): break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
if self.thread:
|
if self.thread:
|
||||||
sys.stdout.write('%s/%s\tthread terminated\r' % (time.strftime('%H:%M:%S', time.gmtime()), self.id))
|
succ_rate = try_div(success_count, job_count)*100
|
||||||
sys.stdout.flush()
|
avg_succ_t = try_div(duration_success_total, success_count)
|
||||||
|
avg_fail_t = try_div(duration_total-duration_success_total, job_count-success_count)
|
||||||
|
avg_t = try_div(duration_total, job_count)
|
||||||
|
_log("terminated, %d/%d (%.2f%%), avg.time S/F/T %.2f, %.2f, %.2f" \
|
||||||
|
% (success_count, job_count, succ_rate, avg_succ_t, avg_fail_t, avg_t) \
|
||||||
|
, self.id)
|
||||||
|
|
||||||
class Proxywatchd():
|
class Proxywatchd():
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user