From d0e9bcc78a0c4b7e7ec25c9de27b334f49cfa55d Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 26 Jul 2023 09:09:53 -0700 Subject: [PATCH 1/2] Remove Powershell as a backup to `handle.exe` If a user does not have `handle.exe` installed in the `PATH` of their Windows system, a message will be logged once, and then the total handles being used will be set to `0`. Fixes #8700 Follow-up to: * #6614 * #6613 * #8541 (cherry picked from commit 30673071accdafc536c53e0992582499c0736de2) --- .../src/rabbit_mgmt_external_stats.erl | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl b/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl index ce82f2c553fc..87a247c3f6d1 100644 --- a/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl +++ b/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl @@ -108,25 +108,23 @@ get_used_fd({win32, _}, State0) -> case os:find_executable("handle.exe") of false -> State1 = log_fd_warning_once("Could not find handle.exe, using powershell to determine handle count", [], State0), - UsedFd = get_used_fd_via_powershell(Pid), - {State1, UsedFd}; + {State1, 0}; HandleExe -> Args = ["/accepteula", "-s", "-p", Pid], {ok, HandleExeOutput} = rabbit_misc:win32_cmd(HandleExe, Args), case HandleExeOutput of [] -> - State1 = log_fd_warning_once("Could not execute handle.exe, using powershell to determine handle count", [], State0), - UsedFd = get_used_fd_via_powershell(Pid), - {State1, UsedFd}; + State1 = log_fd_warning_once("Could not execute handle.exe, " + "please install from " + "https://learn.microsoft.com/en-us/sysinternals/downloads/handle", [], State0), + {State1, 0}; _ -> case find_files_line(HandleExeOutput) of unknown -> State1 = log_fd_warning_once("handle.exe output did not contain " - "a line beginning with 'File', using " - "powershell to determine used file descriptor " - "count: ~tp", [HandleExeOutput], State0), - UsedFd = get_used_fd_via_powershell(Pid), - {State1, UsedFd}; + "a line beginning with 'File': ~tp", + [HandleExeOutput], State0), + {State1, 0}; UsedFd -> {State0, UsedFd} end @@ -144,11 +142,6 @@ find_files_line(["File " ++ Rest | _T]) -> find_files_line([_H | T]) -> find_files_line(T). -get_used_fd_via_powershell(Pid) -> - Cmd = "Get-Process -Id " ++ Pid ++ " | Select-Object -ExpandProperty HandleCount", - {ok, [Result]} = rabbit_misc:pwsh_cmd(Cmd), - list_to_integer(Result). - -define(SAFE_CALL(Fun, NoProcFailResult), try Fun From bf790642f09ec464c3fac9b393ac8cbd3410614b Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Mon, 31 Jul 2023 15:17:45 -0700 Subject: [PATCH 2/2] Update incorrect warning message (cherry picked from commit d4d1f880b096642a9459b42979d01a0cdde8bad5) --- .../src/rabbit_mgmt_external_stats.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl b/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl index 87a247c3f6d1..4b969553fdc9 100644 --- a/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl +++ b/deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl @@ -104,19 +104,19 @@ get_used_fd({unix, _}, State0) -> %% you will see a list of handles of various types, including network sockets %% shown as file handles to \Device\Afd. get_used_fd({win32, _}, State0) -> + MissingHandleMsg = "Could not execute handle.exe, please install from " + "https://learn.microsoft.com/en-us/sysinternals/downloads/handle", Pid = os:getpid(), case os:find_executable("handle.exe") of false -> - State1 = log_fd_warning_once("Could not find handle.exe, using powershell to determine handle count", [], State0), + State1 = log_fd_warning_once(MissingHandleMsg, [], State0), {State1, 0}; HandleExe -> Args = ["/accepteula", "-s", "-p", Pid], {ok, HandleExeOutput} = rabbit_misc:win32_cmd(HandleExe, Args), case HandleExeOutput of [] -> - State1 = log_fd_warning_once("Could not execute handle.exe, " - "please install from " - "https://learn.microsoft.com/en-us/sysinternals/downloads/handle", [], State0), + State1 = log_fd_warning_once(MissingHandleMsg, [], State0), {State1, 0}; _ -> case find_files_line(HandleExeOutput) of