Skip to content

Commit d34a97a

Browse files
committed
input: initialize cmetrics to zero
Upon initialization, metrics are created to handle generic counters, but since these are not initialized with a proper value with the required label (instance name), the metric is not exposed until the value is updated. Most of the cases the end-user would prefer to see a metric with value zero than skip it. This patch adds the initialization to change the default behavior, now all input metrics registered shows zero when they are exposed. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 2ef1ce5 commit d34a97a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/flb_input.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,6 @@ int flb_input_instance_init(struct flb_input_instance *ins,
482482
struct flb_config *config)
483483
{
484484
int ret;
485-
#ifdef FLB_HAVE_METRICS
486-
const char *name;
487-
#endif
488485
struct mk_list *config_map;
489486
struct flb_input_plugin *p = ins->p;
490487

@@ -497,6 +494,13 @@ int flb_input_instance_init(struct flb_input_instance *ins,
497494
return 0;
498495
}
499496

497+
#ifdef FLB_HAVE_METRICS
498+
uint64_t ts;
499+
char *name;
500+
501+
name = (char *) flb_input_name(ins);
502+
ts = cmt_time_now();
503+
500504
/* CMetrics */
501505
ins->cmt = cmt_create();
502506
if (!ins->cmt) {
@@ -510,17 +514,15 @@ int flb_input_instance_init(struct flb_input_instance *ins,
510514
"fluentbit", "input", "bytes_total",
511515
"Number of input bytes.",
512516
1, (char *[]) {"name"});
517+
cmt_counter_set(ins->cmt_bytes, ts, 0, 1, (char *[]) {name});
518+
513519
ins->cmt_records = cmt_counter_create(ins->cmt,
514520
"fluentbit", "input", "records_total",
515521
"Number of input records.",
516522
1, (char *[]) {"name"});
523+
cmt_counter_set(ins->cmt_records, ts, 0, 1, (char *[]) {name});
517524

518525
/* OLD Metrics */
519-
#ifdef FLB_HAVE_METRICS
520-
/* Get name or alias for the instance */
521-
name = flb_input_name(ins);
522-
523-
/* [OLD METRICS] Create the metrics context */
524526
ins->metrics = flb_metrics_create(name);
525527
if (ins->metrics) {
526528
flb_metrics_add(FLB_METRIC_N_RECORDS, "records", ins->metrics);

0 commit comments

Comments
 (0)