Skip to content

Commit b3f092b

Browse files
cosmo0920edsiper
authored andcommitted
engine: output: Add metrics for displaying the available capacity of chunks as percent
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent bcd3281 commit b3f092b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

include/fluent-bit/flb_output.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ struct flb_output_instance {
370370
struct cmt_gauge *cmt_upstream_total_connections;
371371
/* m: output_upstream_busy_connections */
372372
struct cmt_gauge *cmt_upstream_busy_connections;
373+
/* m: output_chunk_available_capacity_percent */
374+
struct cmt_gauge *cmt_chunk_available_capacity_percent;
373375

374376
/* OLD Metrics API */
375377
#ifdef FLB_HAVE_METRICS

src/flb_engine.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ static inline int handle_output_event(uint64_t ts,
312312
flb_output_name(ins), out_id);
313313
}
314314

315+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
316+
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
317+
((double)ins->total_limit_size))),
318+
1, (char *[]) {name});
319+
315320
flb_task_retry_clean(task, ins);
316321
flb_task_users_dec(task, FLB_TRUE);
317322
}
@@ -321,6 +326,11 @@ static inline int handle_output_event(uint64_t ts,
321326
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
322327
1, (char *[]) {name});
323328

329+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
330+
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
331+
((double)ins->total_limit_size))),
332+
1, (char *[]) {name});
333+
324334
/* OLD metrics API */
325335
#ifdef FLB_HAVE_METRICS
326336
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,
353363
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
354364
1, (char *[]) {name});
355365

366+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
367+
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
368+
((double)ins->total_limit_size))),
369+
1, (char *[]) {name});
370+
356371
/* OLD metrics API */
357372
#ifdef FLB_HAVE_METRICS
358373
flb_metrics_sum(FLB_METRIC_OUT_RETRY_FAILED, 1, ins->metrics);
@@ -409,6 +424,11 @@ static inline int handle_output_event(uint64_t ts,
409424
cmt_counter_add(ins->cmt_retried_records, ts, task->records,
410425
1, (char *[]) {name});
411426

427+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
428+
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
429+
((double)ins->total_limit_size))),
430+
1, (char *[]) {name});
431+
412432
/* OLD metrics API: update the metrics since a new retry is coming */
413433
#ifdef FLB_HAVE_METRICS
414434
flb_metrics_sum(FLB_METRIC_OUT_RETRY, 1, ins->metrics);
@@ -422,6 +442,11 @@ static inline int handle_output_event(uint64_t ts,
422442
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
423443
1, (char *[]) {name});
424444

445+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
446+
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
447+
((double)ins->total_limit_size))),
448+
1, (char *[]) {name});
449+
425450
/* OLD API */
426451
#ifdef FLB_HAVE_METRICS
427452
flb_metrics_sum(FLB_METRIC_OUT_ERROR, 1, ins->metrics);

src/flb_output.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,18 @@ int flb_output_init_all(struct flb_config *config)
12001200
0,
12011201
1, (char *[]) {name});
12021202

1203+
/* output_chunk_available_capacity_percent */
1204+
ins->cmt_chunk_available_capacity_percent = cmt_gauge_create(ins->cmt,
1205+
"fluentbit",
1206+
"output",
1207+
"chunk_available_capacity_percent",
1208+
"Available chunk capacity (percent)",
1209+
1, (char *[]) {"name"});
1210+
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent,
1211+
ts,
1212+
100.0,
1213+
1, (char *[]) {name});
1214+
12031215
/* old API */
12041216
ins->metrics = flb_metrics_create(name);
12051217
if (ins->metrics) {

0 commit comments

Comments
 (0)