feat: 返回redis和celery的一些监控数据
This commit is contained in:
parent
8a388928f0
commit
c0567f5a55
|
@ -6,6 +6,7 @@ from datetime import datetime
|
||||||
from apps.utils.tools import compare_values
|
from apps.utils.tools import compare_values
|
||||||
from apps.utils.models import get_model_info
|
from apps.utils.models import get_model_info
|
||||||
from server.celery import celery_control, celery_inspect
|
from server.celery import celery_control, celery_inspect
|
||||||
|
from django_redis import get_redis_connection
|
||||||
|
|
||||||
|
|
||||||
def delete_auditlog(model, instance_id):
|
def delete_auditlog(model, instance_id):
|
||||||
|
@ -104,7 +105,26 @@ class ServerService:
|
||||||
|
|
||||||
class CeleryMonitor:
|
class CeleryMonitor:
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_stats(cls):
|
def get_info(cls):
|
||||||
|
count_active_task = 0
|
||||||
|
count_scheduled_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 = active_tasks.popitem()
|
||||||
|
count_scheduled_task = len(first_value)
|
||||||
|
print(active_tasks)
|
||||||
return {
|
return {
|
||||||
'stat': celery_inspect.stats(),
|
'count_active_task': count_active_task,
|
||||||
|
'count_scheduled_task': count_scheduled_task,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class RedisMonitor:
|
||||||
|
@classmethod
|
||||||
|
def get_info(cls):
|
||||||
|
conn = get_redis_connection()
|
||||||
|
return conn.info()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from .views import DrfRequestLogViewSet, ServerInfoView, LogView, LogDetailView, index, room, video, DbBackupView, AuditlogViewSet, CeleryInfoView
|
from .views import DrfRequestLogViewSet, ServerInfoView, LogView, LogDetailView, index, room, video, DbBackupView, AuditlogViewSet, CeleryInfoView, RedisInfoView
|
||||||
|
|
||||||
API_BASE_URL = 'api/monitor/'
|
API_BASE_URL = 'api/monitor/'
|
||||||
HTML_BASE_URL = 'monitor/'
|
HTML_BASE_URL = 'monitor/'
|
||||||
|
@ -14,6 +14,7 @@ urlpatterns = [
|
||||||
path(API_BASE_URL + 'dbbackup/', DbBackupView.as_view()),
|
path(API_BASE_URL + 'dbbackup/', DbBackupView.as_view()),
|
||||||
path(API_BASE_URL + 'server/', ServerInfoView.as_view()),
|
path(API_BASE_URL + 'server/', ServerInfoView.as_view()),
|
||||||
path(API_BASE_URL + 'celery/', CeleryInfoView.as_view()),
|
path(API_BASE_URL + 'celery/', CeleryInfoView.as_view()),
|
||||||
|
path(API_BASE_URL + 'redis/', RedisInfoView.as_view()),
|
||||||
path(API_BASE_URL + 'request_log/',
|
path(API_BASE_URL + 'request_log/',
|
||||||
DrfRequestLogViewSet.as_view({'get': 'list'}), name='requestlog_view'),
|
DrfRequestLogViewSet.as_view({'get': 'list'}), name='requestlog_view'),
|
||||||
path(API_BASE_URL + 'auditlog/',
|
path(API_BASE_URL + 'auditlog/',
|
||||||
|
|
|
@ -16,7 +16,7 @@ from apps.monitor.filters import DrfLogFilterSet
|
||||||
from apps.monitor.models import DrfRequestLog, AuditLog
|
from apps.monitor.models import DrfRequestLog, AuditLog
|
||||||
|
|
||||||
from apps.monitor.errors import LOG_NOT_FONED
|
from apps.monitor.errors import LOG_NOT_FONED
|
||||||
from apps.monitor.services import ServerService, CeleryMonitor
|
from apps.monitor.services import ServerService, CeleryMonitor, RedisMonitor
|
||||||
from apps.utils.viewsets import CustomGenericViewSet
|
from apps.utils.viewsets import CustomGenericViewSet
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
@ -45,7 +45,19 @@ class CeleryInfoView(APIView):
|
||||||
|
|
||||||
获取celery状态信息
|
获取celery状态信息
|
||||||
"""
|
"""
|
||||||
return Response(CeleryMonitor.get_stats())
|
return Response(CeleryMonitor.get_info())
|
||||||
|
|
||||||
|
|
||||||
|
class RedisInfoView(APIView):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
获取redis状态信息
|
||||||
|
|
||||||
|
获取redis状态信息
|
||||||
|
"""
|
||||||
|
return Response(RedisMonitor.get_info())
|
||||||
|
|
||||||
|
|
||||||
class ServerInfoView(APIView):
|
class ServerInfoView(APIView):
|
||||||
|
|
Loading…
Reference in New Issue