feat: ops添加celery状态监控
This commit is contained in:
parent
0eb0100e60
commit
239692cbd6
|
@ -1,4 +1,6 @@
|
|||
import psutil
|
||||
from server.celery import celery_inspect
|
||||
from django_redis import get_redis_connection
|
||||
|
||||
class ServerService:
|
||||
@classmethod
|
||||
|
@ -30,3 +32,34 @@ class ServerService:
|
|||
@classmethod
|
||||
def get_full(cls):
|
||||
return {'cpu': cls.get_cpu_dict(), 'memory': cls.get_memory_dict(), 'disk': cls.get_disk_dict()}
|
||||
|
||||
|
||||
class CeleryMonitor:
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
count_active_task = 0
|
||||
count_scheduled_task = 0
|
||||
count_registered_task = 0
|
||||
active_tasks = celery_inspect.active()
|
||||
if active_tasks:
|
||||
_, first_value = active_tasks.popitem()
|
||||
count_active_task = len(first_value)
|
||||
scheduled_tasks = celery_inspect.scheduled()
|
||||
if scheduled_tasks:
|
||||
_, first_value = scheduled_tasks.popitem()
|
||||
count_scheduled_task = len(first_value)
|
||||
registered_tasks = celery_inspect.registered()
|
||||
if registered_tasks:
|
||||
_, first_value = registered_tasks.popitem()
|
||||
count_registered_task = len(first_value)
|
||||
return {
|
||||
'count_active_task': count_active_task,
|
||||
'count_scheduled_task': count_scheduled_task,
|
||||
'count_registered_task': count_registered_task,
|
||||
}
|
||||
|
||||
class RedisMonitor:
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
conn = get_redis_connection()
|
||||
return conn.info()
|
|
@ -2,7 +2,7 @@ from django.urls import path
|
|||
from apps.ops.views import (DrfRequestLogViewSet, CpuView, MemoryView, DiskView, DbBackupDeleteView,
|
||||
LogView, LogDetailView,
|
||||
DbBackupView, ReloadClientGit, ReloadServerGit, ReloadServerOnly,
|
||||
BackupDatabase, BackupMedia, TlogViewSet)
|
||||
BackupDatabase, BackupMedia, TlogViewSet, CeleryInfoView, RedisInfoView)
|
||||
|
||||
API_BASE_URL = 'api/ops/'
|
||||
HTML_BASE_URL = 'ops/'
|
||||
|
@ -19,6 +19,8 @@ urlpatterns = [
|
|||
path(API_BASE_URL + 'server/cpu/', CpuView.as_view()),
|
||||
path(API_BASE_URL + 'server/memory/', MemoryView.as_view()),
|
||||
path(API_BASE_URL + 'server/disk/', DiskView.as_view()),
|
||||
path(API_BASE_URL + 'celery/', CeleryInfoView.as_view()),
|
||||
path(API_BASE_URL + 'redis/', RedisInfoView.as_view()),
|
||||
path(API_BASE_URL + 'request_log/',
|
||||
DrfRequestLogViewSet.as_view({'get': 'list'}), name='requestlog_view'),
|
||||
path(API_BASE_URL + 'tlog/',
|
||||
|
|
|
@ -17,7 +17,7 @@ from rest_framework.exceptions import APIException
|
|||
from apps.ops.tasks import reload_server_git, reload_server_only, reload_web_git, backup_database, backup_media
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from apps.ops.service import ServerService
|
||||
from apps.ops.service import ServerService, CeleryMonitor, RedisMonitor
|
||||
from server.settings import BACKUP_PATH
|
||||
# Create your views here.
|
||||
|
||||
|
@ -253,3 +253,26 @@ class TlogViewSet(ListModelMixin, CustomGenericViewSet):
|
|||
ordering = ['-requested_at']
|
||||
filterset_class = TlogFilterSet
|
||||
search_fields = ['path']
|
||||
|
||||
class CeleryInfoView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""
|
||||
获取celery状态信息
|
||||
|
||||
获取celery状态信息
|
||||
"""
|
||||
return Response(CeleryMonitor.get_info())
|
||||
|
||||
|
||||
class RedisInfoView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""
|
||||
获取redis状态信息
|
||||
|
||||
获取redis状态信息
|
||||
"""
|
||||
return Response(RedisMonitor.get_info())
|
||||
|
|
Loading…
Reference in New Issue