mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-02 14:48:12 +08:00
Rework - configuration now in class - better stop handling under heavy load. - scheduler test - better monitoring - better status reporting
This commit is contained in:
@@ -6,7 +6,8 @@ from django.utils import timezone
|
||||
from blessed import Terminal
|
||||
|
||||
# Local
|
||||
from django_q.core import Stat, RUNNING, STOPPED, redis_client
|
||||
from django_q.core import Stat, redis_client
|
||||
from django_q.conf import Conf
|
||||
|
||||
# TODO add name argument to monitor different clusters
|
||||
|
||||
@@ -42,23 +43,37 @@ def monitor(run_once=False):
|
||||
print(term.clear_eos())
|
||||
for stat in stats:
|
||||
# color status
|
||||
if stat.status == RUNNING:
|
||||
status = term.green(RUNNING)
|
||||
elif stat.status == STOPPED:
|
||||
status = term.red(STOPPED)
|
||||
if stat.status == Conf.WORKING:
|
||||
status = term.green(Conf.WORKING)
|
||||
elif stat.status == Conf.STOPPED:
|
||||
status = term.red(Conf.STOPPED)
|
||||
elif stat.status == Conf.IDLE:
|
||||
status = Conf.IDLE
|
||||
else:
|
||||
status = term.yellow(stat.status)
|
||||
# color q's
|
||||
tasks = stat.task_q_size
|
||||
if tasks > 0:
|
||||
tasks = term.cyan(str(tasks))
|
||||
results = stat.done_q_size
|
||||
if results > 0:
|
||||
results = term.cyan(str(results))
|
||||
# color workers
|
||||
workers = len(stat.workers)
|
||||
if workers < Conf.WORKERS:
|
||||
workers = term.yellow(str(workers))
|
||||
# format uptime
|
||||
uptime = (timezone.now() - stat.tob).total_seconds()
|
||||
hours, remainder = divmod(uptime, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
uptime = '%d:%02d:%02d' % (hours, minutes, seconds)
|
||||
# print to the terminal
|
||||
print(term.move(i, 0) + term.center(stat.host[:col_width - 1], width=col_width - 1))
|
||||
print(term.move(i, 1 * col_width) + term.center(stat.cluster_id, width=col_width - 1))
|
||||
print(term.move(i, 2 * col_width) + term.center(status, width=col_width - 1))
|
||||
print(term.move(i, 3 * col_width) + term.center(len(stat.workers), width=col_width - 1))
|
||||
print(term.move(i, 4 * col_width) + term.center(stat.task_q_size, width=col_width - 1))
|
||||
print(term.move(i, 5 * col_width) + term.center(stat.done_q_size, width=col_width - 1))
|
||||
print(term.move(i, 3 * col_width) + term.center(workers, width=col_width - 1))
|
||||
print(term.move(i, 4 * col_width) + term.center(tasks, width=col_width - 1))
|
||||
print(term.move(i, 5 * col_width) + term.center(results, width=col_width - 1))
|
||||
print(term.move(i, 6 * col_width) + term.center(stat.reincarnations, width=col_width - 1))
|
||||
print(term.move(i, 7 * col_width) + term.center(uptime, width=col_width - 1))
|
||||
i += 1
|
||||
|
||||
Reference in New Issue
Block a user