Skip to content

Commit

Permalink
engine: output: Add metrics for displaying the available capacity of …
Browse files Browse the repository at this point in the history
…chunks as percent

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 19, 2023
1 parent 92b9053 commit ae69af8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
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
25 changes: 25 additions & 0 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
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

0 comments on commit ae69af8

Please sign in to comment.