From bf9369df6d67dae6fe2bab3f632c54945a12a1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Wed, 1 Mar 2023 17:56:16 +0800 Subject: [PATCH] fix router --- apps/iot/src/model/router_model.erl | 49 +++++++++-------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/apps/iot/src/model/router_model.erl b/apps/iot/src/model/router_model.erl index 59b3bcc..eb9be11 100644 --- a/apps/iot/src/model/router_model.erl +++ b/apps/iot/src/model/router_model.erl @@ -76,42 +76,21 @@ table_size() -> %% helper methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -to_map(#host{host_id = HostId, name = Name, model = Model, cell_id = CellId, activated_ts = ActivatedTs, update_ts = UpdateTs, status = Status, - metric = #host_metric{ - cpus = Cpus, - cpu_temperature = CpuTemperature, - memory = #memory_metric{used = MemoryUsed, total = MemoryTotal}, - disk = #disk_metric{used = DiskUsed, total = DiskTotal}, - interfaces = Interfaces}}) -> +to_map(#router{router_id = RouterId, name = Name, status = Status, endpoint = Endpoint}) -> + EndpointInfo = case Endpoint of + undefined -> + #{}; + #http_endpoint{url = Url} -> + #{ + <<"type">> => <<"http">>, + <<"url">> => Url + }; + #kafka_endpoint{} -> + #{} + end, #{ - <<"host_id">> => HostId, + <<"router_id">> => RouterId, <<"name">> => Name, - <<"model">> => Model, - <<"cell_id">> => CellId, - <<"activated_ts">> => ActivatedTs, - <<"update_ts">> => UpdateTs, <<"status">> => Status, - <<"metric">> => #{ - <<"cpus">> => lists:map(fun(#cpu_metric{num = Num, load = Load}) -> - #{<<"num">> => Num, <<"load">> => Load } - end, - Cpus), - <<"cpu_temperature">> => CpuTemperature, - <<"memory">> => #{ - <<"used">> => MemoryUsed, - <<"total">> => MemoryTotal - }, - <<"disk">> => #{ - <<"used">> => DiskUsed, - <<"total">> => DiskTotal - }, - <<"interfaces">> => lists:map(fun(#interface_metric{name = IName, desc = IDesc, status = IStatus, detail = IDetail}) -> - #{ - <<"name">> => IName, - <<"desc">> => IDesc, - <<"status">> => IStatus, - <<"detatil">> => IDetail - } - end, Interfaces) - } + <<"endpoint">> => EndpointInfo }. \ No newline at end of file