Skip to content

Commit

Permalink
feat: 系统任务执行状态自监控能力支持 #7457
Browse files Browse the repository at this point in the history
  • Loading branch information
lTimej committed Jul 5, 2024
1 parent 133a47f commit dead6b4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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),
]
45 changes: 45 additions & 0 deletions gcloud/contrib/monitor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
specific language governing permissions and limitations under the License.
"""

import pyrabbit2
from django.db.models import Q
from django.http import JsonResponse
from django.utils import timezone
Expand Down Expand Up @@ -151,3 +152,47 @@ 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})
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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 dead6b4

Please sign in to comment.