Skip to content

Commit ec7a8c2

Browse files
committed
Merge pull request #1821 from rabbitmq/lrb-update-sysmon_handler
Update to sysmon_handler 1.1.0 (cherry picked from commit b204aaa)
1 parent 1475256 commit ec7a8c2

File tree

3 files changed

+119
-33
lines changed

3 files changed

+119
-33
lines changed

priv/schema/rabbit.schema

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,95 +1360,152 @@ end}.
13601360
%% that are overly busy. Processes with large heaps or that take a
13611361
%% long time to garbage collect will count toward this threshold.
13621362
{mapping, "sysmon_handler.thresholds.busy_processes", "sysmon_handler.process_limit", [
1363-
{default, 30},
1364-
{datatype, integer},
1365-
hidden
1363+
{datatype, integer},
1364+
hidden
13661365
]}.
13671366

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

1388+
{translation, "sysmon_handler.port_limit",
1389+
fun(Conf) ->
1390+
case cuttlefish:conf_get("sysmon_handler.thresholds.busy_ports", Conf, undefined) of
1391+
undefined ->
1392+
cuttlefish:unset();
1393+
Int when is_integer(Int) ->
1394+
Int;
1395+
_ ->
1396+
cuttlefish:invalid("should be a non-negative integer")
1397+
end
1398+
end
1399+
}.
1400+
13771401
%% @doc A process will become busy when it exceeds this amount of time
13781402
%% doing garbage collection.
1379-
%%
1380-
%% NOTE: Enabling this setting can cause performance problems on
1381-
%% multi-core systems.
13821403
%% @see sysmon_handler.thresholds.busy_processes
13831404
{mapping, "sysmon_handler.triggers.process.garbage_collection", "sysmon_handler.gc_ms_limit", [
1384-
{default, off},
13851405
{datatype, [{atom, off},
13861406
{duration, ms}]},
13871407
hidden
13881408
]}.
13891409

13901410
{translation, "sysmon_handler.gc_ms_limit",
1391-
fun(Conf) ->
1392-
case cuttlefish:conf_get("sysmon_handler.triggers.process.garbage_collection", Conf) of
1393-
off -> 0;
1394-
Int -> Int
1395-
end
1396-
end}.
1411+
fun(Conf) ->
1412+
case cuttlefish:conf_get("sysmon_handler.triggers.process.garbage_collection", Conf, undefined) of
1413+
undefined ->
1414+
cuttlefish:unset();
1415+
off ->
1416+
0;
1417+
Int when is_integer(Int) ->
1418+
Int;
1419+
_ ->
1420+
cuttlefish:invalid("should be a non-negative integer")
1421+
end
1422+
end
1423+
}.
13971424

13981425
%% @doc A process will become busy when it exceeds this amount of time
13991426
%% during a single process scheduling & execution cycle.
14001427
{mapping, "sysmon_handler.triggers.process.long_scheduled_execution", "sysmon_handler.schedule_ms_limit", [
1401-
{default, off},
14021428
{datatype, [{atom, off},
14031429
{duration, ms}]},
14041430
hidden
14051431
]}.
14061432

14071433
{translation, "sysmon_handler.schedule_ms_limit",
1408-
fun(Conf) ->
1409-
case cuttlefish:conf_get("sysmon_handler.triggers.process.long_scheduled_execution", Conf) of
1410-
off -> 0;
1411-
Int -> Int
1412-
end
1413-
end}.
1434+
fun(Conf) ->
1435+
case cuttlefish:conf_get("sysmon_handler.triggers.process.long_scheduled_execution", Conf, undefined) of
1436+
undefined ->
1437+
cuttlefish:unset();
1438+
off ->
1439+
0;
1440+
Int when is_integer(Int) ->
1441+
Int;
1442+
_ ->
1443+
cuttlefish:invalid("should be a non-negative integer")
1444+
end
1445+
end
1446+
}.
14141447

14151448
%% @doc A process will become busy when its heap exceeds this size.
14161449
%% @see sysmon_handler.thresholds.busy_processes
14171450
{mapping, "sysmon_handler.triggers.process.heap_size", "sysmon_handler.heap_word_limit", [
1418-
{default, "160444000"},
1419-
{datatype, [bytesize, {atom, off}]},
1451+
{datatype, [{atom, off},
1452+
bytesize]},
14201453
hidden
14211454
]}.
14221455

14231456
{translation, "sysmon_handler.heap_word_limit",
1424-
fun(Conf) ->
1425-
case cuttlefish:conf_get("sysmon_handler.triggers.process.heap_size", Conf) of
1426-
off -> 0;
1427-
Bytes ->
1428-
WordSize = erlang:system_info(wordsize),
1429-
Bytes div WordSize
1457+
fun(Conf) ->
1458+
case cuttlefish:conf_get("sysmon_handler.triggers.process.heap_size", Conf, undefined) of
1459+
undefined ->
1460+
cuttlefish:unset();
1461+
off ->
1462+
0;
1463+
Bytes when is_integer(Bytes) ->
1464+
WordSize = erlang:system_info(wordsize),
1465+
Bytes div WordSize;
1466+
_ ->
1467+
cuttlefish:invalid("should be a non-negative integer")
1468+
end
14301469
end
1431-
end}.
1470+
}.
14321471

14331472
%% @doc Whether ports with full input buffers will be counted as
14341473
%% busy. Ports can represent open files or network sockets.
14351474
%% @see sysmon_handler.thresholds.busy_ports
14361475
{mapping, "sysmon_handler.triggers.port", "sysmon_handler.busy_port", [
1437-
{default, on},
14381476
{datatype, flag},
14391477
hidden
14401478
]}.
14411479

1480+
{translation, "sysmon_handler.busy_port",
1481+
fun(Conf) ->
1482+
case cuttlefish:conf_get("sysmon_handler.triggers.port", Conf, undefined) of
1483+
undefined ->
1484+
cuttlefish:unset();
1485+
Val -> Val
1486+
end
1487+
end
1488+
}.
1489+
14421490
%% @doc Whether distribution ports with full input buffers will be
14431491
%% counted as busy. Distribution ports connect Erlang nodes within a
14441492
%% single cluster.
14451493
%% @see sysmon_handler.thresholds.busy_ports
14461494
{mapping, "sysmon_handler.triggers.distribution_port", "sysmon_handler.busy_dist_port", [
1447-
{default, on},
14481495
{datatype, flag},
14491496
hidden
14501497
]}.
14511498

1499+
{translation, "sysmon_handler.busy_dist_port",
1500+
fun(Conf) ->
1501+
case cuttlefish:conf_get("sysmon_handler.triggers.distribution_port", Conf, undefined) of
1502+
undefined ->
1503+
cuttlefish:unset();
1504+
Val -> Val
1505+
end
1506+
end
1507+
}.
1508+
14521509
% ===============================
14531510
% Validators
14541511
% ===============================

src/rabbit.erl

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

525525
start_apps(Apps, RestartTypes) ->
526526
app_utils:load_applications(Apps),
527+
ensure_sysmon_handler_app_config(),
527528
ConfigEntryDecoder = case application:get_env(rabbit, config_entry_decoder) of
528529
undefined ->
529530
[];
@@ -554,7 +555,6 @@ start_apps(Apps, RestartTypes) ->
554555
PassPhrase
555556
},
556557
decrypt_config(Apps, Algo),
557-
558558
OrderedApps = app_utils:app_dependency_order(Apps, false),
559559
case lists:member(rabbit, Apps) of
560560
false -> rabbit_boot_steps:run_boot_steps(Apps); %% plugin activation
@@ -564,6 +564,30 @@ start_apps(Apps, RestartTypes) ->
564564
handle_app_error(could_not_start),
565565
RestartTypes).
566566

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