diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/fluent-bit/examples/out_lib | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/examples/out_lib')
-rw-r--r-- | src/fluent-bit/examples/out_lib/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/fluent-bit/examples/out_lib/README.md | 6 | ||||
-rw-r--r-- | src/fluent-bit/examples/out_lib/out_lib.c | 94 |
3 files changed, 109 insertions, 0 deletions
diff --git a/src/fluent-bit/examples/out_lib/CMakeLists.txt b/src/fluent-bit/examples/out_lib/CMakeLists.txt new file mode 100644 index 000000000..db04ff1c1 --- /dev/null +++ b/src/fluent-bit/examples/out_lib/CMakeLists.txt @@ -0,0 +1,9 @@ +set(src + ${src} + out_lib.c + ) + +find_package (Threads) +add_executable(out_lib ${src}) +target_link_libraries(out_lib fluent-bit-shared) +target_link_libraries(out_lib ${CMAKE_THREAD_LIBS_INIT}) diff --git a/src/fluent-bit/examples/out_lib/README.md b/src/fluent-bit/examples/out_lib/README.md new file mode 100644 index 000000000..f9fc5a4e7 --- /dev/null +++ b/src/fluent-bit/examples/out_lib/README.md @@ -0,0 +1,6 @@ +# Fluent Bit / Hello World + +This tool uses the Fluent Bit library version to flush data to one of the +registered outputs. + +When using Fluent Bit as a library means the caller becomes the input. diff --git a/src/fluent-bit/examples/out_lib/out_lib.c b/src/fluent-bit/examples/out_lib/out_lib.c new file mode 100644 index 000000000..ada207b0c --- /dev/null +++ b/src/fluent-bit/examples/out_lib/out_lib.c @@ -0,0 +1,94 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit Demo + * =============== + * Copyright (C) 2015-2017 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <fluent-bit.h> +#include <msgpack.h> + +int my_stdout_json(void *record, size_t size, void *data) +{ + printf("[%s]",__FUNCTION__); + printf("%s",(char*)record); + printf("\n"); + + flb_lib_free(record); + return 0; +} + +int my_stdout_msgpack(void* data, size_t size) +{ + printf("[%s]",__FUNCTION__); + msgpack_object_print(stdout, *(msgpack_object*)data); + printf("\n"); + + flb_lib_free(data); + return 0; +} + +int main() +{ + int i; + int n; + char tmp[256]; + flb_ctx_t *ctx; + struct flb_lib_out_cb callback; + int in_ffd; + int out_ffd; + + /* Initialize library */ + ctx = flb_create(); + if (!ctx) { + exit(EXIT_FAILURE); + } + + in_ffd = flb_input(ctx, "lib", NULL); + flb_input_set(ctx, in_ffd, "tag", "test", NULL); + + /* Register my callback function */ + + /* JSON format */ + callback.cb = my_stdout_json; + callback.data = NULL; + + out_ffd = flb_output(ctx, "lib", &callback); + flb_output_set(ctx, out_ffd, "match", "test", "format", "json", NULL); + + /* Msgpack format */ + /* + out_ffd = flb_output(ctx, "lib", my_stdout_msgpack); + flb_output_set(ctx, out_ffd, "match", "test", NULL); + */ + + /* Start the background worker */ + flb_start(ctx); + + /* Push some data */ + for (i = 0; i < 100; i++) { + n = snprintf(tmp, sizeof(tmp) - 1, + "[%f, {\"key\": \"val %i\"}]", + flb_time_now(), i); + flb_lib_push(ctx, in_ffd, tmp, n); + } + + flb_stop(ctx); + + /* Release Resources */ + flb_destroy(ctx); + + return 0; +} |