revert(system): 暂时去掉system组件

pull/5196/head
ibuler 2020-12-09 11:10:28 +08:00 committed by Jiangjie.Bai
parent 4c3a655239
commit b189e363cc
13 changed files with 0 additions and 153 deletions

View File

@ -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',

View File

@ -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 = [

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -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

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class SystemConfig(AppConfig):
name = 'system'

View File

@ -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()),
],
),
]

View File

@ -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)

View File

@ -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',
)

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -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

View File

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.