feat: 增加serverservice
This commit is contained in:
parent
35d001e4e5
commit
16490c5907
|
@ -0,0 +1,32 @@
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
class ServerService:
|
||||||
|
@classmethod
|
||||||
|
def get_memory_dict(cls):
|
||||||
|
ret = {}
|
||||||
|
memory = psutil.virtual_memory()
|
||||||
|
ret['total'] = round(memory.total/1024/1024/1024, 2)
|
||||||
|
ret['used'] = round(memory.used/1024/1024/1024, 2)
|
||||||
|
ret['percent'] = memory.percent
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cpu_dict(cls):
|
||||||
|
ret = {}
|
||||||
|
ret['lcount'] = psutil.cpu_count()
|
||||||
|
ret['count'] = psutil.cpu_count(logical=False)
|
||||||
|
ret['percent'] = psutil.cpu_percent(interval=1)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_disk_dict(cls):
|
||||||
|
ret = {}
|
||||||
|
disk = psutil.disk_usage('/')
|
||||||
|
ret['total'] = round(disk.total/1024/1024/1024, 2)
|
||||||
|
ret['used'] = round(disk.used/1024/1024/1024, 2)
|
||||||
|
ret['percent'] = disk.percent
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_full(cls):
|
||||||
|
return {'cpu': cls.get_cpu_dict(), 'memory': cls.get_memory_dict(), 'disk': cls.get_disk_dict()}
|
|
@ -16,6 +16,7 @@ from apps.monitor.filters import DrfLogFilterSet
|
||||||
from apps.monitor.models import DrfRequestLog
|
from apps.monitor.models import DrfRequestLog
|
||||||
|
|
||||||
from apps.monitor.errors import LOG_NOT_FONED
|
from apps.monitor.errors import LOG_NOT_FONED
|
||||||
|
from apps.monitor.services import ServerService
|
||||||
from apps.utils.viewsets import CustomGenericViewSet
|
from apps.utils.viewsets import CustomGenericViewSet
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
@ -43,19 +44,7 @@ class ServerInfoView(APIView):
|
||||||
|
|
||||||
cpu/内存/硬盘
|
cpu/内存/硬盘
|
||||||
"""
|
"""
|
||||||
ret = {'cpu': {}, 'memory': {}, 'disk': {}}
|
return Response(ServerService.get_full())
|
||||||
ret['cpu']['count'] = psutil.cpu_count()
|
|
||||||
ret['cpu']['lcount'] = psutil.cpu_count(logical=False)
|
|
||||||
ret['cpu']['percent'] = psutil.cpu_percent(interval=1)
|
|
||||||
memory = psutil.virtual_memory()
|
|
||||||
ret['memory']['total'] = round(memory.total/1024/1024/1024, 2)
|
|
||||||
ret['memory']['used'] = round(memory.used/1024/1024/1024, 2)
|
|
||||||
ret['memory']['percent'] = memory.percent
|
|
||||||
disk = psutil.disk_usage('/')
|
|
||||||
ret['disk']['total'] = round(disk.total/1024/1024/1024, 2)
|
|
||||||
ret['disk']['used'] = round(disk.used/1024/1024/1024, 2)
|
|
||||||
ret['disk']['percent'] = disk.percent
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_list(file_path):
|
def get_file_list(file_path):
|
||||||
|
|
Loading…
Reference in New Issue