33% %% @copyright (C) 2024, REDGREAT
44% %% @doc
55% %%
6- % %% eadm Controller
6+ % %% eadm 系统信息查询
77% %%
88% %% @end
99% %% Created : 2024-01-25 09:18:34
1212-author (" wangcw" ).
1313
1414% %%===================================================================
15- % %% Application callbacks
15+ % %% 函数导出
1616% %%===================================================================
1717-export ([index /1 ,route_table /1 ]).
1818
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
3131index (#{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+
3579index (#{auth_data := #{<<" authed" >> := false }}) ->
3680 {redirect , " /login" }.
3781
@@ -44,16 +88,16 @@ index(#{auth_data := #{<<"authed">> := false}}) ->
4488route_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
5195route_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;
100144to_string (I ) when erlang :is_integer (I ) ->
101145 SCode = erlang :integer_to_binary (I ),
102146 << <<" StatusCode: " >>/binary ,
103- SCode /binary >>;
147+ SCode /binary >>;
104148to_string (B ) -> B .
0 commit comments