2525% % as observed by RabbitMQ.
2626
2727% % Used by `/metrics` and `/metrics/per-object`.
28- -define (METRIC_NAME_PREFIX , " rabbitmq_" ).
28+ -define (METRIC_NAME_PREFIX , << " rabbitmq_" >> ).
2929
3030% % Used by `/metrics/detailed` endpoint
31- -define (DETAILED_METRIC_NAME_PREFIX , " rabbitmq_detailed_" ).
31+ -define (DETAILED_METRIC_NAME_PREFIX , << " rabbitmq_detailed_" >> ).
3232
3333% % ==The source of these metrics can be found in the rabbit_core_metrics module==
3434% % The relevant files are:
@@ -328,7 +328,8 @@ identity_info() ->
328328 }.
329329
330330add_metric_family ({Name , Type , Help , Metrics }, Callback ) ->
331- Callback (create_mf (? METRIC_NAME (Name ), Help , Type , Metrics )).
331+ MN = <<? METRIC_NAME_PREFIX /binary , (prometheus_model_helpers :metric_name (Name ))/binary >>,
332+ Callback (create_mf (MN , Help , Type , Metrics )).
332333
333334mf (Callback , Prefix , Contents , Data ) ->
334335 [begin
@@ -340,7 +341,7 @@ mf(Callback, Prefix, Contents, Data) ->
340341 end ,
341342 Callback (
342343 create_mf (
343- [ Prefix , prometheus_model_helpers :metric_name (Name )] ,
344+ << Prefix / binary , ( prometheus_model_helpers :metric_name (Name ))/ binary >> ,
344345 Help ,
345346 catch_boolean (Type ),
346347 ? MODULE ,
@@ -357,7 +358,7 @@ mf(Callback, Prefix, Contents, Data) ->
357358 end ,
358359 Callback (
359360 create_mf (
360- [ Prefix , prometheus_model_helpers :metric_name (Name )] ,
361+ << Prefix / binary , ( prometheus_model_helpers :metric_name (Name ))/ binary >> ,
361362 Help ,
362363 catch_boolean (Type ),
363364 ? MODULE ,
@@ -369,7 +370,7 @@ mf(Callback, Prefix, Contents, Data) ->
369370mf_totals (Callback , Name , Type , Help , Size ) ->
370371 Callback (
371372 create_mf (
372- ? METRIC_NAME ( Name ),
373+ << ? METRIC_NAME_PREFIX / binary , ( prometheus_model_helpers : metric_name ( Name ))/ binary >> ,
373374 Help ,
374375 catch_boolean (Type ),
375376 Size
@@ -383,28 +384,36 @@ labels(Item) ->
383384 label (element (1 , Item )).
384385
385386label (# resource {virtual_host = VHost , kind = exchange , name = Name }) ->
386- [{ vhost , VHost }, { exchange , Name }] ;
387+ << " vhost= \" " , VHost / binary , " \" , exchange= \" " , Name / binary , " \" " >> ;
387388label (# resource {virtual_host = VHost , kind = queue , name = Name }) ->
388- [{ vhost , VHost }, { queue , Name }] ;
389+ << " vhost= \" " , VHost / binary , " \" , queue= \" " , Name / binary , " \" " >> ;
389390label ({P , {# resource {virtual_host = QVHost , kind = queue , name = QName },
390391 # resource {virtual_host = EVHost , kind = exchange , name = EName }}}) when is_pid (P ) ->
391392 % % channel_queue_exchange_metrics {channel_id, {queue_id, exchange_id}}
392- [{channel , P }, {queue_vhost , QVHost }, {queue , QName },
393- {exchange_vhost , EVHost }, {exchange , EName }];
393+ <<" channel=\" " , (iolist_to_binary (pid_to_list (P )))/binary , " \" ," ,
394+ " queue_vhost=\" " , QVHost /binary , " \" ," ,
395+ " queue=\" " , QName /binary , " \" ," ,
396+ " exchange_vhost=\" " , EVHost /binary , " \" ," ,
397+ " exchange=\" " , EName /binary , " \" "
398+ >>;
394399label ({RemoteAddress , Username , Protocol }) when is_binary (RemoteAddress ), is_binary (Username ),
395400 is_atom (Protocol ) ->
396401 lists :filter (fun ({_ , V }) ->
397402 V =/= <<>>
398403 end , [{remote_address , RemoteAddress }, {username , Username },
399404 {protocol , atom_to_binary (Protocol , utf8 )}]);
400405label ({I1 , I2 }) ->
401- label (I1 ) ++ label (I2 );
406+ case {label (I1 ), label (I2 )} of
407+ {<<>>, L } -> L ;
408+ {L , <<>>} -> L ;
409+ {L1 , L2 } -> <<L1 /binary , " ," , L2 /binary >>
410+ end ;
402411label (P ) when is_pid (P ) ->
403- [{ channel , P }] ;
412+ << " channel= \" " , ( iolist_to_binary ( pid_to_list ( P )))/ binary , " \" " >> ;
404413label (A ) when is_atom (A ) ->
405414 case is_protocol (A ) of
406- true -> [{ protocol , atom_to_binary (A , utf8 )}] ;
407- false -> []
415+ true -> << " protocol= \" " , ( atom_to_binary (A , utf8 ))/ binary , " \" " >> ;
416+ false -> <<>>
408417 end .
409418
410419is_protocol (P ) ->
0 commit comments