소스 검색

实现Guest性能模型

James Iter 9 년 전
부모
커밋
73b9dbbcbb
3개의 변경된 파일140개의 추가작업 그리고 8개의 파일을 삭제
  1. 7 7
      misc/init.sql
  2. 126 0
      models/Performance.py
  3. 7 1
      models/__init__.py

+ 7 - 7
misc/init.sql

@@ -185,7 +185,7 @@ ALTER TABLE traffic ADD INDEX (tx_packets);
 ALTER TABLE traffic ADD INDEX (timestamp);
 
 
-CREATE TABLE IF NOT EXISTS disk_performance(
+CREATE TABLE IF NOT EXISTS disk_io(
     id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
     guest_uuid CHAR(36) NOT NULL,
     dev VARCHAR(36) NOT NULL,
@@ -198,10 +198,10 @@ CREATE TABLE IF NOT EXISTS disk_performance(
     ENGINE=Innodb
     DEFAULT CHARSET=utf8;
 
-ALTER TABLE disk_performance ADD INDEX (guest_uuid);
-ALTER TABLE disk_performance ADD INDEX (rd_req);
-ALTER TABLE disk_performance ADD INDEX (rd_bytes);
-ALTER TABLE disk_performance ADD INDEX (wr_req);
-ALTER TABLE disk_performance ADD INDEX (wr_bytes);
-ALTER TABLE disk_performance ADD INDEX (timestamp);
+ALTER TABLE disk_io ADD INDEX (guest_uuid);
+ALTER TABLE disk_io ADD INDEX (rd_req);
+ALTER TABLE disk_io ADD INDEX (rd_bytes);
+ALTER TABLE disk_io ADD INDEX (wr_req);
+ALTER TABLE disk_io ADD INDEX (wr_bytes);
+ALTER TABLE disk_io ADD INDEX (timestamp);
 

+ 126 - 0
models/Performance.py

@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+import jimit as ji
+
+from models import ORM, FilterFieldType
+
+
+__author__ = 'James Iter'
+__date__ = '2017/6/28'
+__contact__ = 'james.iter.cn@gmail.com'
+__copyright__ = '(c) 2017 by James Iter.'
+
+
+class CPUMemory(ORM):
+
+    _table_name = 'cpu_memory'
+    _primary_key = 'id'
+
+    def __init__(self):
+        super(CPUMemory, self).__init__()
+        self.id = 0
+        self.guest_uuid = None
+        self.cpu_load = None
+        self.memory_available = None
+        self.memory_unused = None
+        self.timestamp = ji.Common.tus()
+
+    @staticmethod
+    def get_filter_keywords():
+        return {
+            'id': FilterFieldType.INT.value,
+            'guest_uuid': FilterFieldType.STR.value,
+            'cpu_load': FilterFieldType.INT.value,
+            'timestamp': FilterFieldType.INT.value
+        }
+
+    @staticmethod
+    def get_allow_update_keywords():
+        return []
+
+    @staticmethod
+    def get_allow_content_search_keywords():
+        return []
+
+
+class Traffic(ORM):
+
+    _table_name = 'traffic'
+    _primary_key = 'id'
+
+    def __init__(self):
+        super(Traffic, self).__init__()
+        self.id = 0
+        self.guest_uuid = None
+        self.name = None
+        self.rx_bytes = None
+        self.rx_packets = None
+        self.rx_errs = None
+        self.rx_drop = None
+        self.tx_bytes = None
+        self.tx_packets = None
+        self.tx_errs = None
+        self.tx_drop = None
+        self.timestamp = ji.Common.tus()
+
+    @staticmethod
+    def get_filter_keywords():
+        return {
+            'id': FilterFieldType.INT.value,
+            'guest_uuid': FilterFieldType.STR.value,
+            'name': FilterFieldType.STR.value,
+            'rx_bytes': FilterFieldType.INT.value,
+            'rx_packets': FilterFieldType.INT.value,
+            'tx_bytes': FilterFieldType.INT.value,
+            'tx_packets': FilterFieldType.INT.value,
+            'timestamp': FilterFieldType.INT.value
+        }
+
+    @staticmethod
+    def get_allow_update_keywords():
+        return []
+
+    @staticmethod
+    def get_allow_content_search_keywords():
+        return []
+
+
+class DiskIO(ORM):
+
+    _table_name = 'disk_io'
+    _primary_key = 'id'
+
+    def __init__(self):
+        super(DiskIO, self).__init__()
+        self.id = 0
+        self.guest_uuid = None
+        self.dev = None
+        self.rd_req = None
+        self.rd_bytes = None
+        self.wr_req = None
+        self.wr_bytes = None
+        self.timestamp = ji.Common.tus()
+
+    @staticmethod
+    def get_filter_keywords():
+        return {
+            'id': FilterFieldType.INT.value,
+            'guest_uuid': FilterFieldType.STR.value,
+            'dev': FilterFieldType.STR.value,
+            'rd_req': FilterFieldType.INT.value,
+            'rd_bytes': FilterFieldType.INT.value,
+            'wr_req': FilterFieldType.INT.value,
+            'wr_bytes': FilterFieldType.INT.value,
+            'timestamp': FilterFieldType.INT.value
+        }
+
+    @staticmethod
+    def get_allow_update_keywords():
+        return []
+
+    @staticmethod
+    def get_allow_content_search_keywords():
+        return []
+

+ 7 - 1
models/__init__.py

@@ -63,6 +63,12 @@ from event_processor import (
     EventProcessor
 )
 
+from Performance import (
+    CPUMemory,
+    Traffic,
+    DiskIO
+)
+
 
 __author__ = 'James Iter'
 __date__ = '2017/3/21'
@@ -73,7 +79,7 @@ __copyright__ = '(c) 2017 by James Iter.'
 __all__ = [
     'Rules', 'Utils', 'Init', 'Database', 'FilterFieldType', 'Filter', 'EmitKind', 'GuestState', 'DiskState',
     'LogLevel', 'ORM', 'Config', 'Guest', 'Disk', 'BootJob', 'OperateRule', 'OSTemplate', 'GuestXML', 'Log',
-    'EventProcessor', 'ResponseState'
+    'EventProcessor', 'ResponseState', 'CPUMemory', 'Traffic', 'DiskIO'
 ]