@@ -98,39 +98,45 @@ emit_mf_metrics(Fd, #'MetricFamily'{name=Name, metric = Metrics}) ->
9898
9999emit_metric (Fd , Name , # 'Metric' {label = Labels ,
100100 counter = # 'Counter' {value = Value }}) ->
101- emit_series (Fd , Name , Labels , Value );
101+ emit_series (Fd , Name , labels_string ( labels_stringify ( Labels )) , Value );
102102emit_metric (Fd , Name , # 'Metric' {label = Labels ,
103103 gauge = # 'Gauge' {value = Value }}) ->
104- emit_series (Fd , Name , Labels , Value );
104+ emit_series (Fd , Name , labels_string ( labels_stringify ( Labels )) , Value );
105105emit_metric (Fd , Name , # 'Metric' {label = Labels ,
106106 untyped = # 'Untyped' {value = Value }}) ->
107- emit_series (Fd , Name , Labels , Value );
107+ emit_series (Fd , Name , labels_string ( labels_stringify ( Labels )) , Value );
108108emit_metric (Fd , Name , # 'Metric' {label = Labels ,
109109 summary = # 'Summary' {sample_count = Count ,
110110 sample_sum = Sum ,
111111 quantile = Quantiles }}) ->
112- emit_series (Fd , [Name , " _count" ], Labels , Count ),
113- emit_series (Fd , [Name , " _sum" ], Labels , Sum ),
112+ StringLabels = labels_stringify (Labels ),
113+ LString = labels_string (StringLabels ),
114+ emit_series (Fd , [Name , " _count" ], LString , Count ),
115+ emit_series (Fd , [Name , " _sum" ], LString , Sum ),
114116 [
115117 emit_series (
116118 Fd , [Name ],
117- Labels ++ [# 'LabelPair' {name = " quantile" , value = io_lib :format (" ~p " , [QN ])}],
119+ labels_string (StringLabels ++
120+ labels_stringify ([# 'LabelPair' {name = " quantile" , value = io_lib :format (" ~p " , [QN ])}])),
118121 QV )
119122 || # 'Quantile' {quantile = QN , value = QV } <- Quantiles
120123 ];
121124emit_metric (Fd , Name , # 'Metric' {label = Labels ,
122125 histogram = # 'Histogram' {sample_count = Count ,
123126 sample_sum = Sum ,
124127 bucket = Buckets }}) ->
125- [emit_histogram_bucket (Fd , Name , Labels , Bucket ) || Bucket <- Buckets ],
126- emit_series (Fd , [Name , " _count" ], Labels , Count ),
127- emit_series (Fd , [Name , " _sum" ], Labels , Sum ).
128+ StringLabels = labels_stringify (Labels ),
129+ LString = labels_string (StringLabels ),
130+ [emit_histogram_bucket (Fd , Name , StringLabels , Bucket ) || Bucket <- Buckets ],
131+ emit_series (Fd , [Name , " _count" ], LString , Count ),
132+ emit_series (Fd , [Name , " _sum" ], LString , Sum ).
128133
129- emit_histogram_bucket (Fd , Name , Labels , # 'Bucket' {cumulative_count = BCount ,
134+ emit_histogram_bucket (Fd , Name , StringLabels , # 'Bucket' {cumulative_count = BCount ,
130135 upper_bound = BBound }) ->
131136 BLValue = bound_to_label_value (BBound ),
132137 emit_series (Fd , [Name , " _bucket" ],
133- Labels ++ [# 'LabelPair' {name = " le" , value = BLValue }], BCount ).
138+ labels_string (StringLabels ++
139+ labels_stringify ([# 'LabelPair' {name = " le" , value = BLValue }])), BCount ).
134140
135141string_type ('COUNTER' ) ->
136142 " counter" ;
@@ -143,21 +149,21 @@ string_type('HISTOGRAM') ->
143149string_type ('UNTYPED' ) ->
144150 " untyped" .
145151
146- labels_string ([]) -> " " ;
147- labels_string (Labels ) ->
152+ labels_stringify (Labels ) ->
148153 Fun = fun (# 'LabelPair' {name = Name , value = Value }) ->
149154 [Name , " =\" " , escape_label_value (Value ), " \" " ]
150155 end ,
151- [" {" , join (" ," , lists :map (Fun , Labels )), " }" ].
156+ lists :map (Fun , Labels ).
157+
158+ labels_string ([]) -> " " ;
159+ labels_string (Labels ) ->
160+ [" {" , join (" ," , Labels ), " }" ].
152161
153- emit_series (Fd , Name , Labels , undefined ) ->
154- LString = labels_string (Labels ),
162+ emit_series (Fd , Name , LString , undefined ) ->
155163 file :write (Fd , [Name , LString , " NaN\n " ]);
156- emit_series (Fd , Name , Labels , Value ) when is_integer (Value ) ->
157- LString = labels_string (Labels ),
164+ emit_series (Fd , Name , LString , Value ) when is_integer (Value ) ->
158165 file :write (Fd , [Name , LString , " " , integer_to_list (Value ) , " \n " ]);
159- emit_series (Fd , Name , Labels , Value ) ->
160- LString = labels_string (Labels ),
166+ emit_series (Fd , Name , LString , Value ) ->
161167 file :write (Fd , [Name , LString , " " , io_lib :format (" ~p " , [Value ]) , " \n " ]).
162168
163169% % @private
0 commit comments