sys info1
This commit is contained in:
0
Django/db.sqlite3
Normal file
0
Django/db.sqlite3
Normal file
0
Django/info/__init__.py
Normal file
0
Django/info/__init__.py
Normal file
BIN
Django/info/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
Django/info/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Django/info/__pycache__/serializers.cpython-39.pyc
Normal file
BIN
Django/info/__pycache__/serializers.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Django/info/__pycache__/urls.cpython-39.pyc
Normal file
BIN
Django/info/__pycache__/urls.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Django/info/__pycache__/views.cpython-39.pyc
Normal file
BIN
Django/info/__pycache__/views.cpython-39.pyc
Normal file
Binary file not shown.
3
Django/info/admin.py
Normal file
3
Django/info/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
Django/info/apps.py
Normal file
6
Django/info/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class InfoConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "info"
|
||||
0
Django/info/migrations/__init__.py
Normal file
0
Django/info/migrations/__init__.py
Normal file
3
Django/info/models.py
Normal file
3
Django/info/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
24
Django/info/serializers.py
Normal file
24
Django/info/serializers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
class MemoryInfoSerializer(serializers.Serializer):
|
||||
total = serializers.IntegerField()
|
||||
available = serializers.IntegerField()
|
||||
percent = serializers.FloatField()
|
||||
used = serializers.IntegerField()
|
||||
free = serializers.IntegerField()
|
||||
active = serializers.IntegerField()
|
||||
inactive = serializers.IntegerField()
|
||||
buffers = serializers.IntegerField()
|
||||
cached = serializers.IntegerField()
|
||||
shared = serializers.IntegerField()
|
||||
|
||||
|
||||
class CpuInfoSerializer(serializers.Serializer):
|
||||
info = serializers.FloatField()
|
||||
|
||||
class HardInfoSerializer(serializers.Serializer):
|
||||
total = serializers.IntegerField()
|
||||
used = serializers.IntegerField()
|
||||
free = serializers.IntegerField()
|
||||
percent = serializers.FloatField()
|
||||
|
||||
3
Django/info/tests.py
Normal file
3
Django/info/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
Django/info/urls.py
Normal file
7
Django/info/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from .views import *
|
||||
urlpatterns = [
|
||||
path("memory", MemoryInfoView.as_view(),name="memory"),
|
||||
path("cpu", CpuInfoView.as_view(),name="cpu"),
|
||||
path("hard",HardInfoView.as_view(),name='hard'),
|
||||
]
|
||||
34
Django/info/views.py
Normal file
34
Django/info/views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from .serializers import *
|
||||
import psutil
|
||||
import os
|
||||
# Create your views here.
|
||||
|
||||
class MemoryInfoView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
memo_info = psutil.virtual_memory()._asdict()
|
||||
seri = MemoryInfoSerializer(data=memo_info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
|
||||
class CpuInfoView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
cpu_info = psutil.cpu_percent()
|
||||
info = {"info":cpu_info}
|
||||
seri= CpuInfoSerializer(data=info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
class HardInfoView(APIView):
|
||||
def get(self,request,*args,**kwargs):
|
||||
hard_info = psutil.disk_usage(os.getcwd())._asdict()
|
||||
seri = HardInfoSerializer(data=hard_info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
22
Django/manage.py
Executable file
22
Django/manage.py
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sysinfo.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user