out_lib: support metrics input
@@ -149,6 +149,19 @@ static void out_lib_flush(struct flb_event_chunk *event_chunk,
data_size = alloc_size;
break;
case FLB_OUT_LIB_FMT_JSON:
+#ifdef FLB_HAVE_METRICS
+ if (event_chunk->type == FLB_EVENT_TYPE_METRIC) {
+ alloc_size = (off - last_off) + 4096;
+ buf = flb_msgpack_to_json_str(alloc_size, &result.data);
+ if (buf == NULL) {
+ msgpack_unpacked_destroy(&result);
+ FLB_OUTPUT_RETURN(FLB_ERROR);
+ }
+ data_size = strlen(buf);
+ data_for_user = buf;
+ }
+ else {
+#endif
/* JSON is larger than msgpack */
alloc_size = (off - last_off) + 128;
@@ -174,6 +187,9 @@ static void out_lib_flush(struct flb_event_chunk *event_chunk,
flb_free(buf);
data_for_user = out_buf;
data_size = len;
+#ifdef FLB_HAVE_METRICS
+ }
+#endif
break;
}
@@ -201,5 +217,6 @@ struct flb_output_plugin out_lib_plugin = {
.cb_init = out_lib_init,
.cb_flush = out_lib_flush,
.cb_exit = out_lib_exit,
+ .event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS,
.flags = 0,
};
