diff --git a/apps/iot/include/iot.hrl b/apps/iot/include/iot.hrl index 90bbbbe..4bf4116 100644 --- a/apps/iot/include/iot.hrl +++ b/apps/iot/include/iot.hrl @@ -48,15 +48,6 @@ status }). -%% 主机指标 --record(host_metrics, { - cpus = [], - cpu_temperature = 0, - memory = #memory_metric{}, - disk = #disk_metric{}, - interfaces = [] -}). - %% 主机定义 -record(host, { %% ID @@ -67,15 +58,28 @@ model :: binary(), %% 单元网格编号 cell_id :: integer(), - %% 接入设备数 - terminal_num = 0 :: integer(), - %% 服务器指标 - metrics = #host_metrics{}, %% 接入时间 activated_ts = 0 :: integer(), %% 最后上线时间 update_ts = 0 :: integer(), - status = 0 :: integer() + %% 主机状态 + status = ?HOST_STATUS_INACTIVE :: integer() +}). + +%% 主机指标 +-record(host_metric, { + %% ID + id :: binary(), + %% cpu相关 + cpus = [], + %% cpu温度 + cpu_temperature = 0, + %% 内存状态 + memory = #memory_metric{}, + %% 硬盘状态 + disk = #disk_metric{}, + %% 接口状态 + interfaces = [] }). %% 终端表 @@ -101,23 +105,21 @@ }). %% 微服务表 --record(micro_service, { - %% ID +-record(microservice, { + %% ID, 基于UUID生成 id :: binary(), %% 关联主机 host_id :: binary(), %% 名称 name :: binary(), - %% 产品ID,枚举类型 - product_id :: integer(), - %% 厂商ID,枚举类型 - vendor_id :: integer(), - %% 型号 - model :: binary(), - %% 所在单元ID,管理系统负责 - cell_id :: integer(), - %% 终端状态 - status = 0 :: integer(), - %% 最后上线时间 - update_ts = 0 :: integer() + %% 类型 + category :: binary(), + %% 应用对象 + apply_object :: binary(), + %% 版本 + version :: binary(), + %% 执行次数 + execute_count = 0, + %% 部署时间 + deploy_ts = 0 :: integer() }). \ No newline at end of file diff --git a/apps/iot/src/iot_mnesia.erl b/apps/iot/src/iot_mnesia.erl index db2247b..f890b6e 100644 --- a/apps/iot/src/iot_mnesia.erl +++ b/apps/iot/src/iot_mnesia.erl @@ -22,8 +22,9 @@ init_database() -> %% 创建schema ok = mnesia:create_schema([node()]), ok = mnesia:start(), - %% 创建数据库表 + %% 创建数据库表 + %% 主机表 mnesia:create_table(host, [ {attributes, record_info(fields, host)}, {record_name, host}, @@ -31,9 +32,26 @@ init_database() -> {type, set} ]), + %% 主机指标 + mnesia:create_table(host_metric, [ + {attributes, record_info(fields, host_metric)}, + {record_name, host_metric}, + {disc_copies, [node()]}, + {type, set} + ]), + + %% 主机终端管理 mnesia:create_table(terminal, [ {attributes, record_info(fields, terminal)}, - {record_name, host}, + {record_name, terminal}, + {disc_copies, [node()]}, + {type, set} + ]), + + %% 主机微服务管理 + mnesia:create_table(microservice, [ + {attributes, record_info(fields, microservice)}, + {record_name, microservice}, {disc_copies, [node()]}, {type, set} ]), @@ -56,10 +74,8 @@ copy_database(MasterNode) when is_atom(MasterNode) -> mnesia:change_table_copy_type(schema, node(), disc_copies), %% 增加表的分区复制 - mnesia:add_table_copy(booking, node(), ram_copies), - mnesia:add_table_copy(calendar, node(), ram_copies), - mnesia:add_table_copy(app, node(), ram_copies), - mnesia:add_table_copy(fake_app, node(), ram_copies), - mnesia:add_table_copy(app_extra, node(), ram_copies), - mnesia:add_table_copy(app_calendar, node(), ram_copies), + mnesia:add_table_copy(host, node(), ram_copies), + mnesia:add_table_copy(host_metric, node(), ram_copies), + mnesia:add_table_copy(terminal, node(), ram_copies), + mnesia:add_table_copy(microservice, node(), ram_copies), ok. \ No newline at end of file