22
33/* Fluent Bit
44 * ==========
5- * Copyright (C) 2019 The Fluent Bit Authors
5+ * Copyright (C) 2019-2020 The Fluent Bit Authors
66 * Copyright (C) 2015-2018 Treasure Data Inc.
77 *
88 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -60,7 +60,7 @@ static struct flb_hs_buf *metrics_get_latest()
6060}
6161
6262/* Delete unused metrics, note that we only care about the latest node */
63- int cleanup_metrics ()
63+ static int cleanup_metrics ()
6464{
6565 int c = 0 ;
6666 struct mk_list * tmp ;
@@ -126,6 +126,7 @@ static void cb_mq_metrics(mk_mq_t *queue, void *data, size_t size)
126126 buf = flb_malloc (sizeof (struct flb_hs_buf ));
127127 if (!buf ) {
128128 flb_errno ();
129+ flb_sds_destroy (out_data );
129130 return ;
130131 }
131132 buf -> users = 0 ;
@@ -141,13 +142,15 @@ static void cb_mq_metrics(mk_mq_t *queue, void *data, size_t size)
141142}
142143
143144int string_cmp (const void * a_arg , const void * b_arg ) {
144- char * a = * (char * * )a_arg ;
145- char * b = * (char * * )b_arg ;
145+ char * a = * (char * * )a_arg ;
146+ char * b = * (char * * )b_arg ;
147+
146148 return strcmp (a , b );
147149}
148150
149151size_t extract_metric_name_end_position (char * s ) {
150152 int i ;
153+
151154 for (i = 0 ; i < flb_sds_len (s ); i ++ ) {
152155 if (s [i ] == '{' ) {
153156 return i ;
@@ -157,41 +160,51 @@ size_t extract_metric_name_end_position(char *s) {
157160}
158161
159162int is_same_metric (char * s1 , char * s2 ) {
160- int i ;
161- int p1 = extract_metric_name_end_position (s1 );
162- int p2 = extract_metric_name_end_position (s2 );
163- if (p1 != p2 ) {
164- return 0 ;
165- }
166- for (i = 0 ; i < p1 ; i ++ ) {
167- if (s1 [i ] != s2 [i ]) {
168- return 0 ;
163+ int i ;
164+ int p1 = extract_metric_name_end_position (s1 );
165+ int p2 = extract_metric_name_end_position (s2 );
166+
167+ if (p1 != p2 ) {
168+ return 0 ;
169+ }
170+
171+ for (i = 0 ; i < p1 ; i ++ ) {
172+ if (s1 [i ] != s2 [i ]) {
173+ return 0 ;
174+ }
169175 }
170- }
171- return 1 ;
176+ return 1 ;
172177}
173178
174179/* derive HELP text from metricname */
175180/* if help text length > 128, increase init memory for metric_helptxt */
176181flb_sds_t metrics_help_txt (char * metric_name , flb_sds_t * metric_helptxt )
177182{
178- if (strstr (metric_name , "input_bytes" )) {
183+ if (strstr (metric_name , "input_bytes" )) {
179184 return flb_sds_cat (* metric_helptxt , " Number of input bytes.\n" , 24 );
180- } else if (strstr (metric_name , "input_records" )) {
185+ }
186+ else if (strstr (metric_name , "input_records" )) {
181187 return flb_sds_cat (* metric_helptxt , " Number of input records.\n" , 26 );
182- } else if (strstr (metric_name , "output_bytes" )) {
188+ }
189+ else if (strstr (metric_name , "output_bytes" )) {
183190 return flb_sds_cat (* metric_helptxt , " Number of output bytes.\n" , 25 );
184- } else if (strstr (metric_name , "output_records" )) {
191+ }
192+ else if (strstr (metric_name , "output_records" )) {
185193 return flb_sds_cat (* metric_helptxt , " Number of output records.\n" , 27 );
186- } else if (strstr (metric_name , "output_errors" )) {
194+ }
195+ else if (strstr (metric_name , "output_errors" )) {
187196 return flb_sds_cat (* metric_helptxt , " Number of output errors.\n" , 26 );
188- } else if (strstr (metric_name , "output_retries_failed" )) {
197+ }
198+ else if (strstr (metric_name , "output_retries_failed" )) {
189199 return flb_sds_cat (* metric_helptxt , " Number of output retries failed.\n" , 34 );
190- } else if (strstr (metric_name , "output_retries" )) {
200+ }
201+ else if (strstr (metric_name , "output_retries" )) {
191202 return flb_sds_cat (* metric_helptxt , " Number of output retries.\n" , 27 );
192- } else if (strstr (metric_name , "output_proc_records" )) {
203+ }
204+ else if (strstr (metric_name , "output_proc_records" )) {
193205 return flb_sds_cat (* metric_helptxt , " Number of processed output records.\n" , 37 );
194- } else if (strstr (metric_name , "output_proc_bytes" )) {
206+ }
207+ else if (strstr (metric_name , "output_proc_bytes" )) {
195208 return flb_sds_cat (* metric_helptxt , " Number of processed output bytes.\n" , 35 );
196209 }
197210 else {
@@ -473,7 +486,8 @@ int api_v1_metrics(struct flb_hs *hs)
473486 pthread_key_create (& hs_metrics_key , NULL );
474487
475488 /* Create a message queue */
476- hs -> qid = mk_mq_create (hs -> ctx , "/metrics" , cb_mq_metrics , NULL );
489+ hs -> qid_metrics = mk_mq_create (hs -> ctx , "/metrics" ,
490+ cb_mq_metrics , NULL );
477491
478492 /* HTTP end-points */
479493 mk_vhost_handler (hs -> ctx , hs -> vid , "/api/v1/metrics/prometheus" ,
0 commit comments