Skip to content

Commit b204aaa

Browse files
authored
Merge pull request #1821 from rabbitmq/lrb-update-sysmon_handler
Update to sysmon_handler 1.1.0
2 parents c8d0430 + a3f0b3f commit b204aaa

File tree

4 files changed

+203
-794
lines changed

4 files changed

+203
-794
lines changed

priv/schema/rabbit.schema

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,95 +1363,152 @@ end}.
13631363
%% that are overly busy. Processes with large heaps or that take a
13641364
%% long time to garbage collect will count toward this threshold.
13651365
{mapping, "sysmon_handler.thresholds.busy_processes", "sysmon_handler.process_limit", [
1366-
{default, 30},
1367-
{datatype, integer},
1368-
hidden
1366+
{datatype, integer},
1367+
hidden
13691368
]}.
13701369

1370+
{translation, "sysmon_handler.process_limit",
1371+
fun(Conf) ->
1372+
case cuttlefish:conf_get("sysmon_handler.thresholds.busy_processes", Conf, undefined) of
1373+
undefined ->
1374+
cuttlefish:unset();
1375+
Int when is_integer(Int) ->
1376+
Int;
1377+
_ ->
1378+
cuttlefish:invalid("should be a non-negative integer")
1379+
end
1380+
end
1381+
}.
1382+
13711383
%% @doc The threshold at which to warn about the number of ports that
13721384
%% are overly busy. Ports with full input buffers count toward this
13731385
%% threshold.
13741386
{mapping, "sysmon_handler.thresholds.busy_ports", "sysmon_handler.port_limit", [
1375-
{default, 2},
13761387
{datatype, integer},
13771388
hidden
13781389
]}.
13791390

1391+
{translation, "sysmon_handler.port_limit",
1392+
fun(Conf) ->
1393+
case cuttlefish:conf_get("sysmon_handler.thresholds.busy_ports", Conf, undefined) of
1394+
undefined ->
1395+
cuttlefish:unset();
1396+
Int when is_integer(Int) ->
1397+
Int;
1398+
_ ->
1399+
cuttlefish:invalid("should be a non-negative integer")
1400+
end
1401+
end
1402+
}.
1403+
13801404
%% @doc A process will become busy when it exceeds this amount of time
13811405
%% doing garbage collection.
1382-
%%
1383-
%% NOTE: Enabling this setting can cause performance problems on
1384-
%% multi-core systems.
13851406
%% @see sysmon_handler.thresholds.busy_processes
13861407
{mapping, "sysmon_handler.triggers.process.garbage_collection", "sysmon_handler.gc_ms_limit", [
1387-
{default, off},
13881408
{datatype, [{atom, off},
13891409
{duration, ms}]},
13901410
hidden
13911411
]}.
13921412

13931413
{translation, "sysmon_handler.gc_ms_limit",
1394-
fun(Conf) ->
1395-
case cuttlefish:conf_get("sysmon_handler.triggers.process.garbage_collection", Conf) of
1396-
off -> 0;
1397-
Int -> Int
1398-
end
1399-
end}.
1414+
fun(Conf) ->
1415+
case cuttlefish:conf_get("sysmon_handler.triggers.process.garbage_collection", Conf, undefined) of
1416+
undefined ->
1417+
cuttlefish:unset();
1418+
off ->
1419+
0;
1420+
Int when is_integer(Int) ->
1421+
Int;
1422+
_ ->
1423+
cuttlefish:invalid("should be a non-negative integer")
1424+
end
1425+
end
1426+
}.
14001427

14011428
%% @doc A process will become busy when it exceeds this amount of time
14021429
%% during a single process scheduling & execution cycle.
14031430
{mapping, "sysmon_handler.triggers.process.long_scheduled_execution", "sysmon_handler.schedule_ms_limit", [
1404-
{default, off},
14051431
{datatype, [{atom, off},
14061432
{duration, ms}]},
14071433
hidden
14081434
]}.
14091435

14101436
{translation, "sysmon_handler.schedule_ms_limit",
1411-
fun(Conf) ->
1412-
case cuttlefish:conf_get("sysmon_handler.triggers.process.long_scheduled_execution", Conf) of
1413-
off -> 0;
1414-
Int -> Int
1415-
end
1416-
end}.
1437+
fun(Conf) ->
1438+
case cuttlefish:conf_get("sysmon_handler.triggers.process.long_scheduled_execution", Conf, undefined) of
1439+
undefined ->
1440+
cuttlefish:unset();
1441+
off ->
1442+
0;
1443+
Int when is_integer(Int) ->
1444+
Int;
1445+
_ ->
1446+
cuttlefish:invalid("should be a non-negative integer")
1447+
end
1448+
end
1449+
}.
14171450

14181451
%% @doc A process will become busy when its heap exceeds this size.
14191452
%% @see sysmon_handler.thresholds.busy_processes
14201453
{mapping, "sysmon_handler.triggers.process.heap_size", "sysmon_handler.heap_word_limit", [
1421-
{default, "160444000"},
1422-
{datatype, [bytesize, {atom, off}]},
1454+
{datatype, [{atom, off},
1455+
bytesize]},
14231456
hidden
14241457
]}.
14251458

14261459
{translation, "sysmon_handler.heap_word_limit",
1427-
fun(Conf) ->
1428-
case cuttlefish:conf_get("sysmon_handler.triggers.process.heap_size", Conf) of
1429-
off -> 0;
1430-
Bytes ->
1431-
WordSize = erlang:system_info(wordsize),
1432-
Bytes div WordSize
1460+
fun(Conf) ->
1461+
case cuttlefish:conf_get("sysmon_handler.triggers.process.heap_size", Conf, undefined) of
1462+
undefined ->
1463+
cuttlefish:unset();
1464+
off ->
1465+
0;
1466+
Bytes when is_integer(Bytes) ->
1467+
WordSize = erlang:system_info(wordsize),
1468+
Bytes div WordSize;
1469+
_ ->
1470+
cuttlefish:invalid("should be a non-negative integer")
1471+
end
14331472
end
1434-
end}.
1473+
}.
14351474

14361475
%% @doc Whether ports with full input buffers will be counted as
14371476
%% busy. Ports can represent open files or network sockets.
14381477
%% @see sysmon_handler.thresholds.busy_ports
14391478
{mapping, "sysmon_handler.triggers.port", "sysmon_handler.busy_port", [
1440-
{default, on},
14411479
{datatype, flag},
14421480
hidden
14431481
]}.
14441482

1483+
{translation, "sysmon_handler.busy_port",
1484+
fun(Conf) ->
1485+
case cuttlefish:conf_get("sysmon_handler.triggers.port", Conf, undefined) of
1486+
undefined ->
1487+
cuttlefish:unset();
1488+
Val -> Val
1489+
end
1490+
end
1491+
}.
1492+
14451493
%% @doc Whether distribution ports with full input buffers will be
14461494
%% counted as busy. Distribution ports connect Erlang nodes within a
14471495
%% single cluster.
14481496
%% @see sysmon_handler.thresholds.busy_ports
14491497
{mapping, "sysmon_handler.triggers.distribution_port", "sysmon_handler.busy_dist_port", [
1450-
{default, on},
14511498
{datatype, flag},
14521499
hidden
14531500
]}.
14541501

1502+
{translation, "sysmon_handler.busy_dist_port",
1503+
fun(Conf) ->
1504+
case cuttlefish:conf_get("sysmon_handler.triggers.distribution_port", Conf, undefined) of
1505+
undefined ->
1506+
cuttlefish:unset();
1507+
Val -> Val
1508+
end
1509+
end
1510+
}.
1511+
14551512
% ===============================
14561513
% Validators
14571514
% ===============================

src/rabbit.erl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ start_apps(Apps) ->
523523

524524
start_apps(Apps, RestartTypes) ->
525525
app_utils:load_applications(Apps),
526+
ensure_sysmon_handler_app_config(),
526527
ConfigEntryDecoder = case application:get_env(rabbit, config_entry_decoder) of
527528
undefined ->
528529
[];
@@ -553,7 +554,6 @@ start_apps(Apps, RestartTypes) ->
553554
PassPhrase
554555
},
555556
decrypt_config(Apps, Algo),
556-
557557
OrderedApps = app_utils:app_dependency_order(Apps, false),
558558
case lists:member(rabbit, Apps) of
559559
false -> rabbit_boot_steps:run_boot_steps(Apps); %% plugin activation
@@ -563,6 +563,30 @@ start_apps(Apps, RestartTypes) ->
563563
handle_app_error(could_not_start),
564564
RestartTypes).
565565

566+
%% rabbitmq/rabbitmq-server#952
567+
%% This function is to be called after configuration has been optionally generated
568+
%% and the sysmon_handler application loaded, but not started. It will ensure that
569+
%% sane defaults are used for configuration settings that haven't been set by the
570+
%% user
571+
ensure_sysmon_handler_app_config() ->
572+
Defaults = [
573+
{process_limit, 100},
574+
{port_limit, 100},
575+
{gc_ms_limit, 0},
576+
{schedule_ms_limit, 0},
577+
{heap_word_limit, 10485760},
578+
{busy_port, false},
579+
{busy_dist_port, true}
580+
],
581+
lists:foreach(fun({K, V}) ->
582+
case application:get_env(sysmon_handler, K) of
583+
undefined ->
584+
application:set_env(sysmon_handler, K, V);
585+
_ ->
586+
ok
587+
end
588+
end, Defaults).
589+
566590
%% This function retrieves the correct IoDevice for requesting
567591
%% input. The problem with using the default IoDevice is that
568592
%% the Erlang shell prevents us from getting the input.

src/rabbit_sysmon_handler.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ handle_event({monitor, PidOrPort, Type, Info}, State=#state{timer_ref=TimerRef})
9191
{Fmt, Args} = format_pretty_proc_or_port_info(PidOrPort),
9292
rabbit_log:warning("~p ~w ~w " ++ Fmt ++ " ~w", [?MODULE, Type, PidOrPort] ++ Args ++ [Info]),
9393
{ok, State#state{timer_ref=NewTimerRef}};
94+
handle_event({suppressed, Type, Info}, State=#state{timer_ref=TimerRef}) ->
95+
%% Reset the inactivity timeout
96+
NewTimerRef = reset_timer(TimerRef),
97+
rabbit_log:debug("~p encountered a suppressed event of type ~w: ~w", [?MODULE, Type, Info]),
98+
{ok, State#state{timer_ref=NewTimerRef}};
9499
handle_event(Event, State=#state{timer_ref=TimerRef}) ->
95100
NewTimerRef = reset_timer(TimerRef),
96101
rabbit_log:warning("~p unhandled event: ~p", [?MODULE, Event]),

0 commit comments

Comments
 (0)