diff --git a/gcloud/contrib/monitor/urls.py b/gcloud/contrib/monitor/urls.py index 4ebebef3f..493ba34bf 100644 --- a/gcloud/contrib/monitor/urls.py +++ b/gcloud/contrib/monitor/urls.py @@ -19,4 +19,6 @@ url(r"^get_failed_task/$", views.get_failed_task), url(r"^get_executing_task/$", views.get_executing_task), url(r"^get_schedule_times/$", views.get_schedule_times), + url(r"^get_mq_overview/$", views.get_mq_overview), + url(r"^get_mq_data/$", views.get_mq_data), ] diff --git a/gcloud/contrib/monitor/views.py b/gcloud/contrib/monitor/views.py index 06f5379dc..5a253e1c8 100644 --- a/gcloud/contrib/monitor/views.py +++ b/gcloud/contrib/monitor/views.py @@ -20,7 +20,7 @@ from gcloud.iam_auth.intercept import iam_intercept from gcloud.iam_auth.view_interceptors.statistics import StatisticsViewInpterceptor from gcloud.taskflow3.models import TaskFlowInstance - +import pyrabbit2 @require_GET @iam_intercept(StatisticsViewInpterceptor()) @@ -151,3 +151,33 @@ def get_schedule_times(request): for task in tasks ] return JsonResponse({"result": True, "data": schedule_times}) + +@require_GET +@iam_intercept(StatisticsViewInpterceptor()) +def get_mq_overview(request): + """ + 获取mq总览 + """ + data = {} + cl = pyrabbit2.Client("localhost:15672", "guest", "guest") + overview = cl.get_overview() + data = { + "totals":{ + "ready": overview["queue_totals"]["messages_ready"], + "unacked": overview["queue_totals"]["messages_unacknowledged"], + "total": overview["queue_totals"]["messages"] + }, + "global_totals": overview["object_totals"], + "nodes": cl.get_nodes() + } + return JsonResponse({"result": True, "data": data}) + +@require_GET +@iam_intercept(StatisticsViewInpterceptor()) +def get_mq_data(request): + """ + 获取mq数据 + """ + cl = pyrabbit2.Client("localhost:15672", "guest", "guest") + data = {vhost: [{"vhost": vhost, "queue_name": queue["name"], "message_count": queue["messages"], "queue_state": queue["state"], "messages": cl.get_messages(vhost, queue["name"], count=queue["messages"], requeue=True)} for queue in cl.get_queues(vhost=vhost)] for vhost in cl.get_vhost_names()} + return JsonResponse({"result": True, "data": data}) diff --git a/requirements.txt b/requirements.txt index 7f482bc6e..40d25089c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,6 +36,7 @@ bkstorages==1.0.1 ujson==4.1.0 django-dbconn-retry==0.1.5 pydantic==1.9.1 +pyrabbit2==1.0.7 # monitor django-prometheus==2.1.0