diff --git a/include/fluent-bit/flb_output.h b/include/fluent-bit/flb_output.h index d69de4f9192..838409c383e 100644 --- a/include/fluent-bit/flb_output.h +++ b/include/fluent-bit/flb_output.h @@ -365,6 +365,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 64756c090e4..fc3ba56a26d 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) {