Skip to content

Commit 574f29a

Browse files
committed
out_prometheus_exporter: format metrics
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8120f51 commit 574f29a

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

plugins/out_prometheus_exporter/prom.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
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,
83105
static 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
};

plugins/out_prometheus_exporter/prom_http.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,11 @@ int prom_http_server_start(struct prom_http *ph)
234234
return mk_start(ph->ctx);
235235
}
236236

237-
238237
int prom_http_server_stop(struct prom_http *ph)
239238
{
240239
return mk_stop(ph->ctx);
241240
}
242241

243-
244242
int prom_http_server_mq_push_metrics(struct prom_http *ph,
245243
void *data, size_t size)
246244
{

0 commit comments

Comments
 (0)