Skip to content

Commit 23738b5

Browse files
committed
fix:sysinfo without observer module
1 parent 250069c commit 23738b5

7 files changed

Lines changed: 109 additions & 65 deletions

File tree

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ VOLUME /opt/eadm
3131
EXPOSE 8090
3232

3333
LABEL \
34-
org.label-schema.name="eadm" \
35-
org.label-schema.description="erlang书写自用管理,提供日常数据统计查询。" \
36-
org.label-schema.version="${DOCKER_IMAGE_VERSION:-unknown}" \
37-
org.label-schema.vcs-url="https://github.com/redgreat/eadm" \
38-
org.label-schema.maintainer="wangcw <rubygreat@msn.com>" \
39-
org.label-schema.schema-version="1.0"
34+
org.label-schema.name="eadm" \
35+
org.label-schema.description="erlang书写自用管理,提供日常数据统计查询。" \
36+
org.label-schema.version="${DOCKER_IMAGE_VERSION:-unknown}" \
37+
org.label-schema.vcs-url="https://github.com/redgreat/eadm" \
38+
org.label-schema.maintainer="wangcw <rubygreat@msn.com>" \
39+
org.label-schema.schema-version="1.0"
4040

4141
ENTRYPOINT ["/usr/bin/dumb-init", "-c", "--", "/opt/eadm/docker/docker-entrypoint.sh"]

rebar.config

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
{src_dirs, ["src", "src/controllers"]}.
55

66
{erlydtl_opts, [{doc_root, "src/views"},
7-
{recursive, true},
8-
{libraries, [{nova_erlydtl_inventory, nova_erlydtl_inventory}]},
9-
{default_libraries, [nova_erlydtl_inventory]}
10-
]}.
7+
{recursive, true},
8+
{libraries, [{nova_erlydtl_inventory, nova_erlydtl_inventory}]},
9+
{default_libraries, [nova_erlydtl_inventory]}
10+
]}.
1111

1212
%% Deps
1313
{deps, [
14-
{nova, ".*", {git, "https://github.com/novaframework/nova.git", {branch, "master"}}},
15-
%% {mysql_pool, ".*", {git, "https://github.com/silviucpp/mysql_pool.git", {branch, "master"}}},
16-
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {branch, "devel"}}},
17-
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {branch, "master"}}},
18-
{lager, ".*", {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}},
19-
{ecron, ".*", {git, "https://github.com/zhongwencool/ecron.git", {branch, "main"}}}
20-
]}.
14+
{nova, ".*", {git, "https://github.com/novaframework/nova.git", {branch, "master"}}},
15+
%% {mysql_pool, ".*", {git, "https://github.com/silviucpp/mysql_pool.git", {branch, "master"}}},
16+
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {branch, "devel"}}},
17+
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {branch, "master"}}},
18+
{lager, ".*", {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}},
19+
{ecron, ".*", {git, "https://github.com/zhongwencool/ecron.git", {branch, "main"}}}
20+
]}.
2121

2222
%% Plugins for rebar3
2323
{plugins, [
24-
{rebar3_erlydtl_plugin, ".*", {git, "https://github.com/tsloughter/rebar3_erlydtl_plugin.git", {branch, "master"}}},
25-
{rebar3_nova, ".*", {git, "https://github.com/novaframework/rebar3_nova.git", {branch, "master"}}}
26-
]}.
24+
{rebar3_erlydtl_plugin, ".*", {git, "https://github.com/tsloughter/rebar3_erlydtl_plugin.git", {branch, "master"}}},
25+
{rebar3_nova, ".*", {git, "https://github.com/novaframework/rebar3_nova.git", {branch, "master"}}}
26+
]}.
2727

2828
%% Release profiles
2929
%% To create a release just run
3030
%% rebar3 as prod release
3131
{relx, [{release, {eadm, "0.1.47"},
32-
[eadm, nova, epgsql, poolboy, lager, sasl, inets, runtime_tools]},
33-
{mode, minimal},
34-
{extended_start_script, true},
35-
{sys_config, "config/sys.config"},
36-
{vm_args, "config/vm.args"},
37-
{overlay, [{mkdir, "priv"},
38-
{copy, "priv/", "priv"}
39-
]}
32+
[eadm, nova, epgsql, poolboy, lager, sasl, inets, runtime_tools]},
33+
{mode, minimal},
34+
{extended_start_script, true},
35+
{sys_config, "config/sys.config"},
36+
{vm_args, "config/vm.args"},
37+
{overlay, [{mkdir, "priv"},
38+
{copy, "priv/", "priv"}
39+
]}
4040
]}.
4141

4242
{profiles, [{prod, [{relx, [
@@ -50,7 +50,7 @@
5050
{copy, "docker/vm.args", "config/vm.args"}
5151
]}
5252
]}
53-
]}
53+
]}
5454
]}.
5555

5656
{provider_hooks, [{pre, [{compile, {erlydtl, compile}}]}]}.

release/dockerbuild.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# 提前拉取镜像(反复打包测试时免除每次pull)
55
docker pull alpine:3.21
6-
docker pull erlang:26.2.1-alpine
6+
docker pull erlang:27.2.3-alpine
77

88
# 清理镜像
99
docker stop eadm

src/controllers/eadm_login_controller.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ userinfo(#{auth_data := #{<<"authed">> := true, <<"loginname">> := LoginName}})
8181
"select loginname, username, email
8282
from eadm_user
8383
where loginname = $1
84-
and userstatus = 0
85-
and deleted is false
84+
and userstatus = 0
85+
and deleted is false
8686
limit 1", [LoginName]),
8787
ResList = eadm_utils:pg_as_list(ResData),
8888
{json, ResList}
@@ -145,8 +145,8 @@ userpwd(#{auth_data := #{<<"authed">> := true, <<"loginname">> := LoginName},
145145
updatedat = current_timestamp,
146146
passwd = $2
147147
where loginname = $3
148-
and userstatus = 0
149-
and deleted is false;",
148+
and userstatus = 0
149+
and deleted is false;",
150150
[LoginName, CryptoGram, LoginName]),
151151
{json, [#{<<"Alert">> => unicode:characters_to_binary("密码修改成功!", utf8)}]}
152152
catch

src/controllers/eadm_role_controller.erl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
%% 主函数
2525
%% @end
2626
index(#{auth_data := #{<<"authed">> := true, <<"username">> := UserName,
27-
<<"permission">> := #{<<"usermanage">> := true}}}) ->
27+
<<"permission">> := #{<<"usermanage">> := true}}}) ->
2828
{ok, [{username, UserName}]};
2929

3030
index(#{auth_data := #{<<"permission">> := #{<<"usermanage">> := false}}}) ->
@@ -37,7 +37,7 @@ index(#{auth_data := #{<<"authed">> := false}}) ->
3737
%% 查询返回数据结果
3838
%% @end
3939
search(#{auth_data := #{<<"authed">> := true,
40-
<<"permission">> := #{<<"usermanage">> := true}}}) ->
40+
<<"permission">> := #{<<"usermanage">> := true}}}) ->
4141
try
4242
{ok, ResCol, ResData} = eadm_pgpool:equery(pool_pg,
4343
"select id, rolename, rolestatus, createdat
@@ -85,14 +85,14 @@ add(#{auth_data := #{<<"authed">> := false}}) ->
8585
%% 获取角色权限数据
8686
%% @end
8787
loadpermission(#{auth_data := #{<<"authed">> := true,
88-
<<"permission">> := #{<<"usermanage">> := true}},
89-
bindings := #{<<"roleId">> := RoleId}}) ->
88+
<<"permission">> := #{<<"usermanage">> := true}},
89+
bindings := #{<<"roleId">> := RoleId}}) ->
9090
try
9191
{ok, _, ResData} = eadm_pgpool:equery(pool_pg,
9292
"select rolepermission
9393
from eadm_role
9494
where id = $1
95-
and deleted is false;",
95+
and deleted is false;",
9696
[RoleId]),
9797
RetuenJson = eadm_utils:pg_as_jsondata(ResData),
9898
{json, RetuenJson}
@@ -112,8 +112,8 @@ loadpermission(#{auth_data := #{<<"authed">> := false}}) ->
112112
%% 更新角色权限信息
113113
%% @end
114114
updatepermission(#{auth_data := #{<<"authed">> := true, <<"loginname">> := LoginName,
115-
<<"permission">> := #{<<"usermanage">> := true}},
116-
params := #{<<"roleId">> := RoleId, <<"dashBoard">> := DashBoard, <<"health">> := Health,
115+
<<"permission">> := #{<<"usermanage">> := true}},
116+
params := #{<<"roleId">> := RoleId, <<"dashBoard">> := DashBoard, <<"health">> := Health,
117117
<<"locate">> := Locate, <<"finance">> := Finance, <<"finimp">> := Finimp,
118118
<<"findel">> := Findel, <<"crontab">> := Crontab, <<"userManage">> := Usermanage}}) ->
119119
try
@@ -152,16 +152,16 @@ updatepermission(#{auth_data := #{<<"authed">> := false}}) ->
152152
%% 禁用角色
153153
%% @end
154154
disable(#{auth_data := #{<<"authed">> := true, <<"loginname">> := LoginName,
155-
<<"permission">> := #{<<"usermanage">> := true}},
156-
bindings := #{<<"roleId">> := RoleId}}) ->
155+
<<"permission">> := #{<<"usermanage">> := true}},
156+
bindings := #{<<"roleId">> := RoleId}}) ->
157157
try
158158
eadm_pgpool:equery(pool_pg,
159159
"update eadm_role
160160
set rolestatus = 1 - rolestatus,
161161
updateduser = $1,
162162
updatedat = current_timestamp
163163
where id = $2
164-
and deleted is false;",
164+
and deleted is false;",
165165
[LoginName, RoleId]),
166166
{json, [#{<<"Alert">> => unicode:characters_to_binary("角色启禁用成功!", utf8)}]}
167167
catch
@@ -180,14 +180,14 @@ disable(#{auth_data := #{<<"authed">> := false}}) ->
180180
%% 删除角色数据
181181
%% @end
182182
delete(#{auth_data := #{<<"authed">> := true, <<"loginname">> := LoginName,
183-
<<"permission">> := #{<<"usermanage">> := true}},
184-
bindings := #{<<"roleId">> := RoleId}}) ->
183+
<<"permission">> := #{<<"usermanage">> := true}},
184+
bindings := #{<<"roleId">> := RoleId}}) ->
185185
try
186186
eadm_pgpool:equery(pool_pg,
187187
"update eadm_role
188188
set deleteduser = $1,
189-
deletedat = now(),
190-
deleted = true
189+
deletedat = now(),
190+
deleted = true
191191
where id = $2;",
192192
[LoginName, RoleId]),
193193
{json, [#{<<"Alert">> => unicode:characters_to_binary("角色删除成功!", utf8)}]}
@@ -207,8 +207,8 @@ delete(#{auth_data := #{<<"authed">> := false}}) ->
207207
%% 查询角色列表
208208
%% @end
209209
getrolelist(#{auth_data := #{<<"authed">> := true,
210-
<<"permission">> := #{<<"usermanage">> := true}},
211-
bindings := #{<<"userId">> := UserId}}) ->
210+
<<"permission">> := #{<<"usermanage">> := true}},
211+
bindings := #{<<"userId">> := UserId}}) ->
212212
try
213213
{ok, ResCol, ResData} = eadm_pgpool:equery(pool_pg,
214214
"select a.id, a.rolename, a.createdat

src/controllers/eadm_sys_ports_controller.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ index(_Req) ->
3131
Ports = [ maps:from_list(X) || X <- observer_backend:get_port_list()],
3232
Ports0 = lists:map(fun(A = #{port_id := PortId, connected := Connected}) ->
3333
A#{port_id => erlang:port_to_list(PortId), connected => erlang:pid_to_list(Connected)}
34-
end, Ports),
34+
end, Ports),
3535
{ok, [{ports, Ports0}]}.

src/controllers/eadm_sys_sysinfo_controller.erl

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%%% @copyright (C) 2024, REDGREAT
44
%%% @doc
55
%%%
6-
%%% eadm Controller
6+
%%% eadm 系统信息查询
77
%%%
88
%%% @end
99
%%% Created : 2024-01-25 09:18:34
@@ -12,7 +12,7 @@
1212
-author("wangcw").
1313

1414
%%%===================================================================
15-
%%% Application callbacks
15+
%%% 函数导出
1616
%%%===================================================================
1717
-export([index/1,route_table/1]).
1818

@@ -21,17 +21,61 @@
2121
%%%===================================================================
2222
-include_lib("routing_tree/include/routing_tree.hrl").
2323

24-
%%====================================================================
25-
%% API functions
26-
%%====================================================================
24+
%%%===================================================================
25+
%%% API 函数
26+
%%%===================================================================
2727

2828
%% @doc
2929
%% index
3030
%% @end
3131
index(#{auth_data := #{<<"authed">> := true, <<"username">> := Username}}) ->
32-
SysInfo = observer_backend:sys_info(),
33-
Uptime = observer_lib:to_str({time_ms, proplists:get_value(uptime, SysInfo)}),
34-
{ok, [{sys_info, SysInfo}, {uptime, Uptime}, {username, Username}]};
32+
% SysInfo = observer_backend:sys_info(),
33+
% Uptime = observer_lib:to_str({time_ms, proplists:get_value(uptime, SysInfo)}),
34+
35+
SysInfo = [
36+
{otp_release, erlang:system_info(otp_release)},
37+
{version, erlang:system_info(version)},
38+
{system_architecture, erlang:system_info(system_architecture)},
39+
{wordsize_internal, erlang:system_info({wordsize, internal})},
40+
{wordsize_external, erlang:system_info({wordsize, external})},
41+
{smp_support, erlang:system_info(smp_support)},
42+
{threads, erlang:system_info(threads)},
43+
{thread_pool_size, erlang:system_info(thread_pool_size)},
44+
{logical_processors, erlang:system_info(logical_processors)},
45+
{logical_processors_online, erlang:system_info(logical_processors_online)},
46+
{logical_processors_available, erlang:system_info(logical_processors_available)},
47+
{schedulers, erlang:system_info(schedulers)},
48+
{schedulers_online, erlang:system_info(schedulers_online)},
49+
{schedulers_available, case erlang:system_info(multi_scheduling) of
50+
enabled -> erlang:system_info(schedulers_online);
51+
_ -> 1
52+
end},
53+
{run_queue, erlang:statistics(run_queue)},
54+
{atom_count, erlang:system_info(atom_count)},
55+
{atom_limit, erlang:system_info(atom_limit)},
56+
{process_count, erlang:system_info(process_count)},
57+
{process_limit, erlang:system_info(process_limit)},
58+
{port_count, erlang:system_info(port_count)},
59+
{port_limit, erlang:system_info(port_limit)},
60+
{ets_count, erlang:system_info(ets_count)},
61+
{ets_limit, erlang:system_info(ets_limit)},
62+
{total, erlang:memory(total)},
63+
{processes_used, erlang:memory(processes_used)},
64+
{atom_used, erlang:memory(atom_used)},
65+
{binary, erlang:memory(binary)},
66+
{code, erlang:memory(code)},
67+
{ets, erlang:memory(ets)},
68+
{dist_buf_busy_limit, erlang:system_info(dist_buf_busy_limit)}
69+
],
70+
71+
{{input, IOInput}, {output, IOOutput}} = erlang:statistics(io),
72+
SysInfoWithIO = lists:append(SysInfo, [{io_input, IOInput}, {io_output, IOOutput}]),
73+
74+
{Uptime, _} = erlang:statistics(wall_clock),
75+
UptimeStr = io_lib:format("~p Secs", [Uptime div 1000]),
76+
77+
{ok, [{sys_info, SysInfoWithIO}, {uptime, UptimeStr}, {username, Username}]};
78+
3579
index(#{auth_data := #{<<"authed">> := false}}) ->
3680
{redirect, "/login"}.
3781

@@ -44,16 +88,16 @@ index(#{auth_data := #{<<"authed">> := false}}) ->
4488
route_table(#{auth_data := #{<<"authed">> := true, <<"username">> := Username}}) ->
4589
#host_tree{hosts = Hosts} = persistent_term:get(nova_dispatch),
4690
[Routes|_] = lists:map(fun({Host, #routing_tree{tree = Tree}}) ->
47-
#{"text" => to_string(Host), "children" => flatten_routes(Tree)}
48-
end, Hosts),
91+
#{"text" => to_string(Host), "children" => flatten_routes(Tree)}
92+
end, Hosts),
4993
{ok, [{routes, thoas:encode(Routes)}, {username, Username}], #{view => eadm_sys_routes}};
5094

5195
route_table(#{auth_data := #{<<"authed">> := false}}) ->
5296
{redirect, "/login"}.
5397

54-
%%====================================================================
55-
%% Internal functions
56-
%%====================================================================
98+
%%===================================================================
99+
%% 内部函数
100+
%%===================================================================
57101

58102
%%--------------------------------------------------------------------
59103
%% @private
@@ -100,5 +144,5 @@ to_string(S) when erlang:is_list(S) -> S;
100144
to_string(I) when erlang:is_integer(I) ->
101145
SCode = erlang:integer_to_binary(I),
102146
<< <<"StatusCode: ">>/binary,
103-
SCode/binary >>;
147+
SCode/binary >>;
104148
to_string(B) -> B.

0 commit comments

Comments
 (0)