Преглед изворни кода

实现宿主机信息接收

James Iter пре 9 година
родитељ
комит
0e10bd1d66
3 измењених фајлова са 77 додато и 2 уклоњено
  1. 3 2
      docs/todo.md
  2. 70 0
      misc/init.sql
  3. 4 0
      models/event_processor.py

+ 3 - 2
docs/todo.md

@@ -15,9 +15,10 @@
 - [ ] 增加模板镜像上传功能
 - [x] 虚拟机加入用户级的重启作业功能
 - [x] 提示待做的启动作业
+- [ ] 密码栏默认隐藏,加入显示开关
 - [ ] 加入 tag 功能
-- [ ] 收集存在于 JimV-N,却不存在于 JimV-C 的 Guest
-- [ ] IP 为空的,允许用户手动补入 Guest 的真实 IP,补入时并检查新 IP 是否可用
+- [x] `不予支持`收集存在于 JimV-N,却不存在于 JimV-C 的 Guest。(无法确定其创建的规范,比如是否使用了规划的分布式文件系统、模板、开启vnc等。这样导致迁移、重置密码、前端ICON显示有问题)
+- [x] `不予支持`IP 为空的,允许用户手动补入 Guest 的真实 IP,补入时并检查新 IP 是否可用
 - [x] 批量添加启动作业
 - [x] 单独写页面展现已有启动作业的虚拟机列表
 - [x] 磁盘页面,默认不显示系统盘,加 CheckBox 来控制

+ 70 - 0
misc/init.sql

@@ -158,6 +158,7 @@ CREATE TABLE IF NOT EXISTS cpu_memory(
 ALTER TABLE cpu_memory ADD INDEX (guest_uuid);
 ALTER TABLE cpu_memory ADD INDEX (cpu_load);
 ALTER TABLE cpu_memory ADD INDEX (timestamp);
+ALTER TABLE cpu_memory ADD INDEX (guest_uuid, timestamp);
 
 
 CREATE TABLE IF NOT EXISTS traffic(
@@ -183,6 +184,7 @@ ALTER TABLE traffic ADD INDEX (rx_packets);
 ALTER TABLE traffic ADD INDEX (tx_bytes);
 ALTER TABLE traffic ADD INDEX (tx_packets);
 ALTER TABLE traffic ADD INDEX (timestamp);
+ALTER TABLE traffic ADD INDEX (guest_uuid, timestamp);
 
 
 CREATE TABLE IF NOT EXISTS disk_io(
@@ -203,4 +205,72 @@ 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);
+ALTER TABLE disk_io ADD INDEX (disk_uuid, timestamp);
+
+
+CREATE TABLE IF NOT EXISTS host_cpu_memory(
+    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+    host_uuid CHAR(36) NOT NULL,
+    cpu_load INT UNSIGNED NOT NULL,
+    memory_available BIGINT UNSIGNED NOT NULL,
+    timestamp BIGINT UNSIGNED NOT NULL,
+    PRIMARY KEY (id))
+    ENGINE=Innodb
+    DEFAULT CHARSET=utf8;
+
+ALTER TABLE host_cpu_memory ADD INDEX (host_uuid);
+ALTER TABLE host_cpu_memory ADD INDEX (timestamp);
+ALTER TABLE host_cpu_memory ADD INDEX (host_uuid, timestamp);
+
+
+CREATE TABLE IF NOT EXISTS host_traffic(
+    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+    host_uuid CHAR(36) NOT NULL,
+    name VARCHAR(36) NOT NULL,
+    rx_bytes BIGINT UNSIGNED NOT NULL,
+    rx_packets BIGINT UNSIGNED NOT NULL,
+    rx_errs BIGINT UNSIGNED NOT NULL,
+    rx_drop BIGINT UNSIGNED NOT NULL,
+    tx_bytes BIGINT UNSIGNED NOT NULL,
+    tx_packets BIGINT UNSIGNED NOT NULL,
+    tx_errs BIGINT UNSIGNED NOT NULL,
+    tx_drop BIGINT UNSIGNED NOT NULL,
+    timestamp BIGINT UNSIGNED NOT NULL,
+    PRIMARY KEY (id))
+    ENGINE=Innodb
+    DEFAULT CHARSET=utf8;
+
+ALTER TABLE host_traffic ADD INDEX (host_uuid);
+ALTER TABLE host_traffic ADD INDEX (rx_bytes);
+ALTER TABLE host_traffic ADD INDEX (rx_packets);
+ALTER TABLE host_traffic ADD INDEX (tx_bytes);
+ALTER TABLE host_traffic ADD INDEX (tx_packets);
+ALTER TABLE host_traffic ADD INDEX (timestamp);
+ALTER TABLE host_traffic ADD INDEX (host_uuid, timestamp);
+
+
+CREATE TABLE IF NOT EXISTS host_disk_usage_io(
+    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+    host_uuid CHAR(36) NOT NULL,
+    mountpoint VARCHAR(255) NOT NULL,
+    used BIGINT UNSIGNED NOT NULL,
+    rd_req BIGINT UNSIGNED NOT NULL,
+    rd_bytes BIGINT UNSIGNED NOT NULL,
+    wr_req BIGINT UNSIGNED NOT NULL,
+    wr_bytes BIGINT UNSIGNED NOT NULL,
+    timestamp BIGINT UNSIGNED NOT NULL,
+    PRIMARY KEY (id))
+    ENGINE=Innodb
+    DEFAULT CHARSET=utf8;
+
+ALTER TABLE host_disk_usage_io ADD INDEX (host_uuid);
+ALTER TABLE host_disk_usage_io ADD INDEX (mountpoint);
+ALTER TABLE host_disk_usage_io ADD INDEX (used);
+ALTER TABLE host_disk_usage_io ADD INDEX (rd_req);
+ALTER TABLE host_disk_usage_io ADD INDEX (rd_bytes);
+ALTER TABLE host_disk_usage_io ADD INDEX (wr_req);
+ALTER TABLE host_disk_usage_io ADD INDEX (wr_bytes);
+ALTER TABLE host_disk_usage_io ADD INDEX (timestamp);
+ALTER TABLE host_disk_usage_io ADD INDEX (host_uuid, mountpoint, timestamp);
+
 

+ 4 - 0
models/event_processor.py

@@ -101,6 +101,10 @@ class EventProcessor(object):
         key = cls.message['message']['node_id']
         value = {
             'hostname': cls.message['host'],
+            'cpu': cls.message['message']['cpu'],
+            'memory': cls.message['message']['memory'],
+            'interfaces': cls.message['message']['interfaces'],
+            'disks': cls.message['message']['disks'],
             'timestamp': ji.Common.ts()
         }