You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2026/10/04 06:12:23 UTC
(couchdb) 01/01: Improve weatherreport checks
This is an automated email from the ASF dual-hosted git repository.
nickva pushed a commit to branch weatherreport-fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit bb9c6ef85026cffbdf2e62ee500b0470c0f3ba88
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Sun Oct 4 02:05:58 2026 -0400
Improve weatherreport checks
For better compatibility use `file:write_file_info/2` instead `touch`. Check if
commands exist with `os:find_executable/1` before running them. Use
`spawn_executable` instead of `spawn` to run the commands.
Co-Authored-By: Robert Newson <rn...@apache.org>
---
src/weatherreport/src/weatherreport_check_disk.erl | 2 +-
.../src/weatherreport_check_memory_use.erl | 2 +-
.../src/weatherreport_check_tcp_queues.erl | 2 +-
src/weatherreport/src/weatherreport_config.erl | 2 +-
src/weatherreport/src/weatherreport_util.erl | 31 ++++++++++++++--------
5 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/weatherreport/src/weatherreport_check_disk.erl b/src/weatherreport/src/weatherreport_check_disk.erl
index 5361ae632..dca84d053 100644
--- a/src/weatherreport/src/weatherreport_check_disk.erl
+++ b/src/weatherreport/src/weatherreport_check_disk.erl
@@ -180,7 +180,7 @@ check_is_file_readable(Directory) ->
%% Check if the directory is mounted with 'noatime'
check_atime(Directory) ->
File = filename:join([Directory, ?TEST_FILE]),
- weatherreport_util:run_command("touch -at 201401010000.00 " ++ File),
+ file:write_file_info(File, #file_info{atime = {{2014, 01, 01}, {0, 0, 0}}}),
{ok, FileInfo1} = file:read_file_info(File),
{ok, S} = file:open(File, [read]),
io:get_line(S, ''),
diff --git a/src/weatherreport/src/weatherreport_check_memory_use.erl b/src/weatherreport/src/weatherreport_check_memory_use.erl
index 04c021381..f18f02bb4 100644
--- a/src/weatherreport/src/weatherreport_check_memory_use.erl
+++ b/src/weatherreport/src/weatherreport_check_memory_use.erl
@@ -52,7 +52,7 @@ valid() ->
-spec check(list()) -> [{atom(), term()}].
check(_Opts) ->
Pid = weatherreport_node:pid(),
- Output = weatherreport_util:run_command("ps -o pmem,rss -p " ++ Pid),
+ Output = weatherreport_util:run_command("ps", ["-o", "pmem,rss", "-p", Pid]),
[_, _, Percent, RealSize | _] = string:tokens(Output, "/n \n"),
Messages = [{info, {process_usage, Percent, RealSize}}],
case weatherreport_util:binary_to_float(list_to_binary(Percent)) >= 90 of
diff --git a/src/weatherreport/src/weatherreport_check_tcp_queues.erl b/src/weatherreport/src/weatherreport_check_tcp_queues.erl
index cc502031b..6ed4ea254 100644
--- a/src/weatherreport/src/weatherreport_check_tcp_queues.erl
+++ b/src/weatherreport/src/weatherreport_check_tcp_queues.erl
@@ -77,7 +77,7 @@ sum_to_message(Sum, Prefix) ->
-spec check(list()) -> [{atom(), term()}].
check(_Opts) ->
- Netstats = weatherreport_util:run_command("netstat"),
+ Netstats = weatherreport_util:run_command("netstat", []),
{SumRecvQ, SumSendQ} = sum_queues(Netstats),
[sum_to_message(SumRecvQ, "recv_q"), sum_to_message(SumSendQ, "send_q")].
diff --git a/src/weatherreport/src/weatherreport_config.erl b/src/weatherreport/src/weatherreport_config.erl
index 6cf9fd533..47a81ab08 100644
--- a/src/weatherreport/src/weatherreport_config.erl
+++ b/src/weatherreport/src/weatherreport_config.erl
@@ -81,7 +81,7 @@ get_vm_env(Key) ->
%% @doc Determines the user/uid that the script is running as.
-spec user() -> string().
user() ->
- case weatherreport_util:run_command("whoami") of
+ case weatherreport_util:run_command("whoami", []) of
[] ->
undefined;
Resp ->
diff --git a/src/weatherreport/src/weatherreport_util.erl b/src/weatherreport/src/weatherreport_util.erl
index c4f9fb42a..8817f8d73 100644
--- a/src/weatherreport/src/weatherreport_util.erl
+++ b/src/weatherreport/src/weatherreport_util.erl
@@ -30,7 +30,7 @@
-module(weatherreport_util).
-export([
short_name/1,
- run_command/1,
+ run_command/2,
binary_to_float/1,
flush_stdout/0,
check_proc_count/3
@@ -46,16 +46,25 @@ short_name(Mod) when is_atom(Mod) ->
%% @doc Runs a shell command and returns the output. stderr is
%% redirected to stdout so its output will be included.
--spec run_command(Command :: iodata()) -> StdOut :: iodata().
-run_command(Command) ->
- weatherreport_log:log(
- node(),
- debug,
- "Running shell command: ~s",
- [Command]
- ),
- Port = open_port({spawn, Command}, [exit_status, stderr_to_stdout]),
- do_read(Port, []).
+-spec run_command(Command :: string(), Args :: [string() | binary()]) -> StdOut :: iodata().
+run_command(Command, Args) ->
+ case os:find_executable(Command) of
+ false ->
+ [];
+ FileName ->
+ weatherreport_log:log(
+ node(),
+ debug,
+ "Running shell command: ~s with args: ~p",
+ [FileName, Args]
+ ),
+ Port = open_port({spawn_executable, FileName}, [
+ {args, Args},
+ exit_status,
+ stderr_to_stdout
+ ]),
+ do_read(Port, [])
+ end.
do_read(Port, Acc) ->
receive