1919 */
2020
2121#include <fluent-bit/flb_output_plugin.h>
22+ #include <cmetrics/cmetrics.h>
23+ #include <cmetrics/cmt_encode_text.h>
24+ #include <cmetrics/cmt_decode_msgpack.h>
2225
2326#include "prom.h"
2427#include "prom_http.h"
@@ -70,9 +73,28 @@ static void cb_prom_flush(const void *data, size_t bytes,
7073 struct flb_config * config )
7174{
7275 int ret ;
76+ cmt_sds_t text ;
77+ struct cmt * cmt ;
7378 struct prom_exporter * ctx = out_context ;
7479
75- ret = prom_http_server_mq_push_metrics (ctx -> http , (char * ) data , bytes );
80+ ret = cmt_decode_msgpack (& cmt , (char * ) data , bytes );
81+ if (ret != 0 ) {
82+ FLB_OUTPUT_RETURN (FLB_ERROR );
83+ }
84+
85+ /* convert to text representation */
86+ text = cmt_encode_text_create (cmt );
87+ if (!text ) {
88+ cmt_destroy (cmt );
89+ FLB_OUTPUT_RETURN (FLB_ERROR );
90+ }
91+ cmt_destroy (cmt );
92+
93+ ret = prom_http_server_mq_push_metrics (ctx -> http ,
94+ (char * ) text ,
95+ flb_sds_len (text ));
96+ cmt_encode_text_destroy (text );
97+
7698 if (ret != 0 ) {
7799 FLB_OUTPUT_RETURN (FLB_ERROR );
78100 }
@@ -83,10 +105,11 @@ static void cb_prom_flush(const void *data, size_t bytes,
83105static int cb_prom_exit (void * data , struct flb_config * config )
84106{
85107 struct prom_exporter * ctx = data ;
86- struct prom_http * ph = ctx -> http ;
87- if (ph ) {
88- prom_http_server_destroy (ph );
89- }
108+
109+ prom_http_server_stop (ctx -> http );
110+ prom_http_server_destroy (ctx -> http );
111+ flb_free (ctx );
112+
90113 return 0 ;
91114}
92115
@@ -113,6 +136,7 @@ struct flb_output_plugin out_prometheus_exporter_plugin = {
113136 .cb_init = cb_prom_init ,
114137 .cb_flush = cb_prom_flush ,
115138 .cb_exit = cb_prom_exit ,
116- .config_map = config_map ,
117139 .flags = FLB_OUTPUT_NET ,
140+ .event_type = FLB_OUTPUT_METRICS ,
141+ .config_map = config_map ,
118142};
0 commit comments