James Iter 9 лет назад
Родитель
Сommit
77add577d9
5 измененных файлов с 28 добавлено и 7 удалено
  1. 2 3
      misc/init.sql
  2. 1 1
      models/__init__.py
  3. 17 0
      models/event_processor.py
  4. 2 3
      models/performance.py
  5. 6 0
      models/status.py

+ 2 - 3
misc/init.sql

@@ -187,8 +187,7 @@ ALTER TABLE traffic ADD INDEX (timestamp);
 
 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,
+    disk_uuid CHAR(36) NOT NULL,
     rd_req BIGINT UNSIGNED NOT NULL,
     rd_bytes BIGINT UNSIGNED NOT NULL,
     wr_req BIGINT UNSIGNED NOT NULL,
@@ -198,7 +197,7 @@ CREATE TABLE IF NOT EXISTS disk_io(
     ENGINE=Innodb
     DEFAULT CHARSET=utf8;
 
-ALTER TABLE disk_io ADD INDEX (guest_uuid);
+ALTER TABLE disk_io ADD INDEX (disk_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);

+ 1 - 1
models/__init__.py

@@ -63,7 +63,7 @@ from event_processor import (
     EventProcessor
 )
 
-from Performance import (
+from performance import (
     CPUMemory,
     Traffic,
     DiskIO

+ 17 - 0
models/event_processor.py

@@ -203,6 +203,20 @@ class EventProcessor(object):
         else:
             pass
 
+    @classmethod
+    def collection_performance_processor(cls):
+        action = cls.message['message']['action']
+        uuid = cls.message['message']['uuid']
+        state = cls.message['type']
+        data = cls.message['message']['data']
+
+        if action == 'create_guest':
+            if state == ResponseState.success.value:
+                # 系统盘的 UUID 与其 Guest 的 UUID 相同
+                cls.disk.uuid = uuid
+        else:
+            pass
+
     @classmethod
     def launch(cls):
         while True:
@@ -232,6 +246,9 @@ class EventProcessor(object):
                 elif cls.message['kind'] == EmitKind.response.value:
                     cls.response_processor()
 
+                elif cls.message['kind'] == EmitKind.collection_performance.value:
+                    cls.collection_performance_processor()
+
                 else:
                     pass
 

+ 2 - 3
models/Performance.py → models/performance.py

@@ -95,7 +95,7 @@ class DiskIO(ORM):
     def __init__(self):
         super(DiskIO, self).__init__()
         self.id = 0
-        self.guest_uuid = None
+        self.disk_uuid = None
         self.dev = None
         self.rd_req = None
         self.rd_bytes = None
@@ -107,8 +107,7 @@ class DiskIO(ORM):
     def get_filter_keywords():
         return {
             'id': FilterFieldType.INT.value,
-            'guest_uuid': FilterFieldType.STR.value,
-            'dev': FilterFieldType.STR.value,
+            'disk_uuid': FilterFieldType.STR.value,
             'rd_req': FilterFieldType.INT.value,
             'rd_bytes': FilterFieldType.INT.value,
             'wr_req': FilterFieldType.INT.value,

+ 6 - 0
models/status.py

@@ -16,6 +16,7 @@ class EmitKind(IntEnum):
     guest_event = 1
     host_event = 2
     response = 3
+    collection_performance = 4
 
 
 class GuestState(IntEnum):
@@ -76,3 +77,8 @@ class OperateRuleKind(IntEnum):
     append_file = 2
 
 
+class CollectionPerformanceDataKind(IntEnum):
+    cpu_memory = 0
+    traffic = 1
+    disk_io = 2
+