From b189e363cc7fbe8a42575910e8d20576c64f9e2b Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 9 Dec 2020 11:10:28 +0800 Subject: [PATCH] =?UTF-8?q?revert(system):=20=E6=9A=82=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E6=8E=89system=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/settings/base.py | 1 - apps/jumpserver/urls.py | 1 - apps/system/__init__.py | 0 apps/system/admin.py | 3 -- apps/system/api.py | 17 ------- apps/system/apps.py | 5 -- apps/system/migrations/0001_initial.py | 26 ---------- apps/system/migrations/__init__.py | 0 apps/system/models.py | 68 -------------------------- apps/system/serializers.py | 12 ----- apps/system/tests.py | 3 -- apps/system/urls.py | 14 ------ apps/system/views.py | 3 -- 13 files changed, 153 deletions(-) delete mode 100644 apps/system/__init__.py delete mode 100644 apps/system/admin.py delete mode 100644 apps/system/api.py delete mode 100644 apps/system/apps.py delete mode 100644 apps/system/migrations/0001_initial.py delete mode 100644 apps/system/migrations/__init__.py delete mode 100644 apps/system/models.py delete mode 100644 apps/system/serializers.py delete mode 100644 apps/system/tests.py delete mode 100644 apps/system/urls.py delete mode 100644 apps/system/views.py diff --git a/apps/jumpserver/settings/base.py b/apps/jumpserver/settings/base.py index db00cb6a2..47b3d7a04 100644 --- a/apps/jumpserver/settings/base.py +++ b/apps/jumpserver/settings/base.py @@ -48,7 +48,6 @@ INSTALLED_APPS = [ 'authentication.apps.AuthenticationConfig', # authentication 'applications.apps.ApplicationsConfig', 'tickets.apps.TicketsConfig', - 'system.apps.SystemConfig', 'jms_oidc_rp', 'rest_framework', 'rest_framework_swagger', diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index dc74bcd14..c6d85b48b 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -23,7 +23,6 @@ api_v1 = [ path('common/', include('common.urls.api_urls', namespace='api-common')), path('applications/', include('applications.urls.api_urls', namespace='api-applications')), path('tickets/', include('tickets.urls.api_urls', namespace='api-tickets')), - path('system/', include('system.urls', namespace='api-system')), ] api_v2 = [ diff --git a/apps/system/__init__.py b/apps/system/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/system/admin.py b/apps/system/admin.py deleted file mode 100644 index 8c38f3f3d..000000000 --- a/apps/system/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/system/api.py b/apps/system/api.py deleted file mode 100644 index d1ebb369c..000000000 --- a/apps/system/api.py +++ /dev/null @@ -1,17 +0,0 @@ -# ~*~ coding: utf-8 ~*~ -from common.permissions import IsOrgAdminOrAppUser -from common.drf.api import JMSBulkModelViewSet -from common.utils import get_logger -from . import serializers -from .models import Stat - -logger = get_logger(__name__) -__all__ = ['StatViewSet'] - - -class StatViewSet(JMSBulkModelViewSet): - queryset = Stat.objects.all() - filter_fields = ('id', 'key', 'value', 'component') - search_fields = filter_fields - permission_classes = (IsOrgAdminOrAppUser,) - serializer_class = serializers.StatSerializer diff --git a/apps/system/apps.py b/apps/system/apps.py deleted file mode 100644 index 5dc4d64bc..000000000 --- a/apps/system/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class SystemConfig(AppConfig): - name = 'system' diff --git a/apps/system/migrations/0001_initial.py b/apps/system/migrations/0001_initial.py deleted file mode 100644 index d4f7ad7a1..000000000 --- a/apps/system/migrations/0001_initial.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.1 on 2020-11-25 06:31 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Stat', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('node', models.CharField(max_length=128)), - ('ip', models.GenericIPAddressField()), - ('component', models.CharField(choices=[('core', 'Core'), ('koko', 'KoKo'), ('guacamole', 'Guacamole'), ('omnidb', 'OmniDB')], max_length=16)), - ('key', models.CharField(db_index=True, max_length=16, verbose_name='Item key')), - ('value', models.FloatField()), - ('datetime', models.DateTimeField()), - ], - ), - ] diff --git a/apps/system/migrations/__init__.py b/apps/system/migrations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/system/models.py b/apps/system/models.py deleted file mode 100644 index 924f60521..000000000 --- a/apps/system/models.py +++ /dev/null @@ -1,68 +0,0 @@ -import time - -from django.db import models -import psutil -from django.utils import timezone - -from django.utils.translation import ugettext_lazy as _ - - -class Stat(models.Model): - class Components(models.TextChoices): - core = 'core', 'Core' - koko = 'koko', 'KoKo' - guacamole = 'guacamole', 'Guacamole' - omnidb = 'omnidb', 'OmniDB' - - class Keys(models.TextChoices): - cpu_load_1 = 'cpu_load', 'CPU load' - memory_used_percent = 'memory_used_percent', _('Memory used percent') - disk_used_percent = 'disk_used_percent', _('Disk used percent') - session_active = 'session_active', _('Session active') - session_processed = 'session_processed', _('Session processed') - - node = models.CharField(max_length=128) - ip = models.GenericIPAddressField() - component = models.CharField(choices=Components.choices, max_length=16) - key = models.CharField(db_index=True, max_length=16, verbose_name=_('Item key')) - value = models.FloatField() - datetime = models.DateTimeField() - - def __str__(self): - return f'{self.key}:{self.value}' - - @staticmethod - def collect_local_stats(): - memory_percent = psutil.virtual_memory().percent - cpu_load = psutil.getloadavg() - cpu_load_1 = round(cpu_load[0], 2) - cpu_load_5 = round(cpu_load[1], 2) - cpu_load_15 = round(cpu_load[2], 2) - cpu_percent = psutil.cpu_percent() - stats = dict( - memory_percent=memory_percent, - cpu_load_1=cpu_load_1, - cpu_load_5=cpu_load_5, - cpu_load_15=cpu_load_15, - cpu_load=cpu_load_1, - cpu_percent=cpu_percent - ) - return stats - - @classmethod - def keep_collect_local_stats(cls): - data = { - 'node': 'core-01', - 'ip': '192.168.1.1', - 'component': 'core' - } - while True: - stats = cls.collect_local_stats() - data['datetime'] = timezone.now() - items = [] - for k, v in stats.items(): - data['key'] = k - data['value'] = v - items.append(cls(**data)) - cls.objects.bulk_create(items, ignore_conflicts=True) - time.sleep(60) diff --git a/apps/system/serializers.py b/apps/system/serializers.py deleted file mode 100644 index e8ada1d15..000000000 --- a/apps/system/serializers.py +++ /dev/null @@ -1,12 +0,0 @@ -from common.drf.serializers import BulkModelSerializer - -from .models import Stat - - -class StatSerializer(BulkModelSerializer): - class Meta: - model = Stat - fields = ( - 'id', 'node', 'ip', 'component', - 'key', 'value', 'datetime', - ) diff --git a/apps/system/tests.py b/apps/system/tests.py deleted file mode 100644 index 7ce503c2d..000000000 --- a/apps/system/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/system/urls.py b/apps/system/urls.py deleted file mode 100644 index dee2db457..000000000 --- a/apps/system/urls.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding:utf-8 -from rest_framework_bulk.routes import BulkRouter - -from . import api - -app_name = 'system' - -router = BulkRouter() -router.register(r'stats', api.StatViewSet, 'stat') - -urlpatterns = [ -] - -urlpatterns += router.urls diff --git a/apps/system/views.py b/apps/system/views.py deleted file mode 100644 index 91ea44a21..000000000 --- a/apps/system/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here.