From b3f092bc435ddd9d0c3b9d76cc4b257611690143 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 18 Oct 2023 19:18:04 +0900 Subject: [PATCH] engine: output: Add metrics for displaying the available capacity of chunks as percent Signed-off-by: Hiroshi Hatake --- include/fluent-bit/flb_output.h | 2 ++ src/flb_engine.c | 25 +++++++++++++++++++++++++ src/flb_output.c | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/fluent-bit/flb_output.h b/include/fluent-bit/flb_output.h index 5978c285679..5dc2bf286b2 100644 --- a/include/fluent-bit/flb_output.h +++ b/include/fluent-bit/flb_output.h @@ -370,6 +370,8 @@ struct flb_output_instance { struct cmt_gauge *cmt_upstream_total_connections; /* m: output_upstream_busy_connections */ struct cmt_gauge *cmt_upstream_busy_connections; + /* m: output_chunk_available_capacity_percent */ + struct cmt_gauge *cmt_chunk_available_capacity_percent; /* OLD Metrics API */ #ifdef FLB_HAVE_METRICS diff --git a/src/flb_engine.c b/src/flb_engine.c index 78be8d5ec8d..5e4fb5d04b4 100644 --- a/src/flb_engine.c +++ b/src/flb_engine.c @@ -312,6 +312,11 @@ static inline int handle_output_event(uint64_t ts, flb_output_name(ins), out_id); } + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts, + (100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/ + ((double)ins->total_limit_size))), + 1, (char *[]) {name}); + flb_task_retry_clean(task, ins); flb_task_users_dec(task, FLB_TRUE); } @@ -321,6 +326,11 @@ static inline int handle_output_event(uint64_t ts, cmt_counter_add(ins->cmt_dropped_records, ts, task->records, 1, (char *[]) {name}); + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts, + (100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/ + ((double)ins->total_limit_size))), + 1, (char *[]) {name}); + /* OLD metrics API */ #ifdef FLB_HAVE_METRICS flb_metrics_sum(FLB_METRIC_OUT_DROPPED_RECORDS, task->records, ins->metrics); @@ -353,6 +363,11 @@ static inline int handle_output_event(uint64_t ts, cmt_counter_add(ins->cmt_dropped_records, ts, task->records, 1, (char *[]) {name}); + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts, + (100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/ + ((double)ins->total_limit_size))), + 1, (char *[]) {name}); + /* OLD metrics API */ #ifdef FLB_HAVE_METRICS flb_metrics_sum(FLB_METRIC_OUT_RETRY_FAILED, 1, ins->metrics); @@ -409,6 +424,11 @@ static inline int handle_output_event(uint64_t ts, cmt_counter_add(ins->cmt_retried_records, ts, task->records, 1, (char *[]) {name}); + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts, + (100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/ + ((double)ins->total_limit_size))), + 1, (char *[]) {name}); + /* OLD metrics API: update the metrics since a new retry is coming */ #ifdef FLB_HAVE_METRICS flb_metrics_sum(FLB_METRIC_OUT_RETRY, 1, ins->metrics); @@ -422,6 +442,11 @@ static inline int handle_output_event(uint64_t ts, cmt_counter_add(ins->cmt_dropped_records, ts, task->records, 1, (char *[]) {name}); + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts, + (100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/ + ((double)ins->total_limit_size))), + 1, (char *[]) {name}); + /* OLD API */ #ifdef FLB_HAVE_METRICS flb_metrics_sum(FLB_METRIC_OUT_ERROR, 1, ins->metrics); diff --git a/src/flb_output.c b/src/flb_output.c index ee50ed80a2a..15daa6c09d4 100644 --- a/src/flb_output.c +++ b/src/flb_output.c @@ -1200,6 +1200,18 @@ int flb_output_init_all(struct flb_config *config) 0, 1, (char *[]) {name}); + /* output_chunk_available_capacity_percent */ + ins->cmt_chunk_available_capacity_percent = cmt_gauge_create(ins->cmt, + "fluentbit", + "output", + "chunk_available_capacity_percent", + "Available chunk capacity (percent)", + 1, (char *[]) {"name"}); + cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, + ts, + 100.0, + 1, (char *[]) {name}); + /* old API */ ins->metrics = flb_metrics_create(name); if (ins->metrics) {