2424
2525-export ([start_link /0 , start /0 , stop /0 , register /2 , set_alarm /1 ,
2626 clear_alarm /1 , get_alarms /0 , get_alarms /1 , get_local_alarms /0 , get_local_alarms /1 , on_node_up /1 , on_node_down /1 ,
27+ format_resource_alarm_source /1 ,
2728 format_as_map /1 , format_as_maps /1 , is_local /1 ]).
2829
2930-export ([init /1 , handle_call /2 , handle_event /2 , handle_info /2 ,
@@ -124,25 +125,23 @@ is_local({file_descriptor_limit, _}) -> true;
124125is_local ({{resource_limit , _Resource , Node }, _ }) when Node =:= node () -> true ;
125126is_local ({{resource_limit , _Resource , Node }, _ }) when Node =/= node () -> false .
126127
128+ -spec format_resource_alarm_source (resource_alarm_source ()) -> iodata ().
129+ format_resource_alarm_source (disk ) ->
130+ ? DISK_SPACE_RESOURCE ;
131+ format_resource_alarm_source (memory ) ->
132+ ? MEMORY_RESOURCE ;
133+ format_resource_alarm_source (Unknown ) ->
134+ io_lib :format (" ~w " , [Unknown ]).
135+
127136-spec format_as_map (alarm ()) -> #{binary () => term ()}.
128137format_as_map (file_descriptor_limit ) ->
129138 #{
130139 <<" resource" >> => ? FILE_DESCRIPTOR_RESOURCE ,
131140 <<" node" >> => node ()
132141 };
133- format_as_map ({resource_limit , disk , Node }) ->
134- #{
135- <<" resource" >> => ? DISK_SPACE_RESOURCE ,
136- <<" node" >> => Node
137- };
138- format_as_map ({resource_limit , memory , Node }) ->
139- #{
140- <<" resource" >> => ? MEMORY_RESOURCE ,
141- <<" node" >> => Node
142- };
143142format_as_map ({resource_limit , Limit , Node }) ->
144143 #{
145- <<" resource" >> => rabbit_data_coercion : to_binary ( Limit ),
144+ <<" resource" >> => iolist_to_binary ( format_resource_alarm_source ( Limit ) ),
146145 <<" node" >> => Node
147146 }.
148147
@@ -237,7 +236,7 @@ handle_event({node_down, Node}, #alarms{alarmed_nodes = AN} = State) ->
237236 AlarmsForDeadNode = maps :get (Node , AN , []),
238237 {ok , lists :foldr (fun (Source , AccState ) ->
239238 ? LOG_WARNING (" ~ts resource limit alarm cleared for dead node ~tp " ,
240- [Source , Node ]),
239+ [format_resource_alarm_source ( Source ) , Node ]),
241240 maybe_alert (fun map_unappend /3 , Node , Source , false , AccState )
242241 end , State , AlarmsForDeadNode )};
243242
@@ -283,7 +282,8 @@ maybe_alert(UpdateFun, Node, Source, WasAlertAdded,
283282 end , AN1 ),
284283 case StillHasAlerts of
285284 true -> ok ;
286- false -> ? LOG_WARNING (" ~ts resource limit alarm cleared across the cluster" , [Source ])
285+ false -> ? LOG_WARNING (" ~ts resource limit alarm cleared across the cluster" ,
286+ [format_resource_alarm_source (Source )])
287287 end ,
288288 Alert = {WasAlertAdded , StillHasAlerts , Node },
289289 case node () of
@@ -326,7 +326,7 @@ handle_set_resource_alarm(Source, Node, State) ->
326326 " **********************************************************~n "
327327 " *** Publishers will be blocked until this alarm clears ***~n "
328328 " **********************************************************~n " ,
329- [Source , Node ]),
329+ [format_resource_alarm_source ( Source ) , Node ]),
330330 {ok , maybe_alert (fun map_append /3 , Node , Source , true , State )}.
331331
332332handle_set_alarm ({file_descriptor_limit , []}, State ) ->
@@ -342,7 +342,7 @@ handle_set_alarm(Alarm, State) ->
342342
343343handle_clear_resource_alarm (Source , Node , State ) ->
344344 ? LOG_WARNING (" ~ts resource limit alarm cleared on node ~tp " ,
345- [Source , Node ]),
345+ [format_resource_alarm_source ( Source ) , Node ]),
346346 {ok , maybe_alert (fun map_unappend /3 , Node , Source , false , State )}.
347347
348348handle_clear_alarm (file_descriptor_limit , State ) ->
0 commit comments