Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ static inline int handle_input_event(flb_pipefd_t fd, uint64_t ts,
return 0;
}

static inline double calculate_chunk_capacity_percent(struct flb_output_instance *ins)
{
/* Currently, total_limit_size 0(K|M)B will be translated as no
* limit. So, we need to handle this situation to be unlimited. */
if (ins->total_limit_size <= 0) {
return 100.0;
}

return 100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size));
}

static inline int handle_output_event(uint64_t ts,
struct flb_config *config,
uint64_t val)
Expand Down Expand Up @@ -312,6 +324,10 @@ 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,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

flb_task_retry_clean(task, ins);
flb_task_users_dec(task, FLB_TRUE);
}
Expand All @@ -321,6 +337,10 @@ 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,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_DROPPED_RECORDS, task->records, ins->metrics);
Expand Down Expand Up @@ -353,6 +373,10 @@ 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,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_RETRY_FAILED, 1, ins->metrics);
Expand Down Expand Up @@ -409,6 +433,10 @@ 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,
calculate_chunk_capacity_percent(ins),
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);
Expand All @@ -422,6 +450,10 @@ 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,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_ERROR, 1, ins->metrics);
Expand Down
12 changes: 12 additions & 0 deletions src/flb_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down