Skip to content

Commit

Permalink
feat: 系统任务执行状态自监控能力支持 #7457
Browse files Browse the repository at this point in the history
  • Loading branch information
刘俊 committed Jul 5, 2024
1 parent 133a47f commit 860d33c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gcloud/contrib/monitor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
32 changes: 31 additions & 1 deletion gcloud/contrib/monitor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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})
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 860d33c

Please sign in to comment.