From e8e596ba72a2635704ec1e56a9ede5bd62155717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Thu, 16 Feb 2023 14:24:54 +0800 Subject: [PATCH] fix --- apps/iot/include/iot.hrl | 63 ++++++++++++++++++++++++--- apps/iot/src/model/host_model.erl | 2 +- apps/iot/src/model/terminal_model.erl | 2 +- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/apps/iot/include/iot.hrl b/apps/iot/include/iot.hrl index f3ee775..43cbed6 100644 --- a/apps/iot/include/iot.hrl +++ b/apps/iot/include/iot.hrl @@ -8,19 +8,72 @@ %%%------------------------------------------------------------------- -author("licheng5"). -%% 状态定义 --define(STATUS_INACTIVE, 0). --define(STATUS_ONLINE, 1). --define(STATUS_OFFLINE, 2). --define(STATUS_DELETE, 3). +%% 主机状态定义 +-define(HOST_STATUS_INACTIVE, 0). +-define(HOST_STATUS_ONLINE, 1). +-define(HOST_STATUS_OFFLINE, 2). +-define(HOST_STATUS_DELETE, 3). + +%% cpu相关 +-record(cpu_metric, { + %% cpu编号 + num = 1, + %% 负载 + load = 0 +}). + +%% 内存相关, 单位kb +-record(memory_metric, { + %% 使用量 + used = 0, + %% 总量 + total = 0 +}). + +%% 硬盘相关, 单位kb +-record(disk_metric, { + %% 使用量 + used = 0, + %% 总量 + total = 0 +}). + +%% 接口相关 +-record(interface_metric, { + %% 接口名称 + name = <<>>, + %% 接口详情 + desc = <<>>, + %% 接口状态 + status +}). + +%% 主机指标 +-record(host_metrics, { + cpus = [], + cpu_temperature = 0, + memory = #memory_metric{}, + disk = #disk_metric{}, + interfaces = [] +}). %% 主机定义 -record(host, { + %% ID id :: binary(), + %% 名称 name :: binary(), + %% 型号 model :: binary(), + %% 单元网格编号 cell_id :: integer(), + %% 接入设备数 terminal_num = 0 :: integer(), + %% 服务器指标 + metrics, + %% 接入时间 + activated_ts = 0 :: integer(), + %% 最后上线时间 update_ts = 0 :: integer(), status = 0 :: integer() }). diff --git a/apps/iot/src/model/host_model.erl b/apps/iot/src/model/host_model.erl index f9590df..59a8c9f 100644 --- a/apps/iot/src/model/host_model.erl +++ b/apps/iot/src/model/host_model.erl @@ -39,7 +39,7 @@ insert(Id, Name, Model, CellId) -> cell_id = CellId, terminal_num = 0, update_ts = 0, - status = ?STATUS_INACTIVE + status = ?HOST_STATUS_INACTIVE }, case mnesia:transaction(fun() -> mnesia:write(host, Host, write) end) of diff --git a/apps/iot/src/model/terminal_model.erl b/apps/iot/src/model/terminal_model.erl index 48ef377..1db2963 100644 --- a/apps/iot/src/model/terminal_model.erl +++ b/apps/iot/src/model/terminal_model.erl @@ -36,7 +36,7 @@ insert(Id, HostId, Name, ProductId, VendorId, Model, CellId) -> cell_id = CellId, host_id = HostId, update_ts = 0, - status = ?STATUS_INACTIVE + status = ?HOST_STATUS_INACTIVE }, case mnesia:transaction(fun() -> mnesia:write(terminal, Terminal, write) end) of