Skip to content

Commit 264e436

Browse files
committed
output: 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 output metrics registered shows zero when they are exposed. Signed-off-by: Eduardo Silva <[email protected]>
1 parent d34a97a commit 264e436

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/flb_output.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ int flb_output_init_all(struct flb_config *config)
818818
struct mk_list *config_map;
819819
struct flb_output_instance *ins;
820820
struct flb_output_plugin *p;
821+
uint64_t ts;
821822

822823
/* Retrieve the plugin reference */
823824
mk_list_foreach_safe(head, tmp, &config->outputs) {
@@ -854,50 +855,74 @@ int flb_output_init_all(struct flb_config *config)
854855
/* Get name or alias for the instance */
855856
name = (char *) flb_output_name(ins);
856857

858+
/* get timestamp */
859+
ts = cmt_time_now();
860+
857861
/* CMetrics */
858862
ins->cmt = cmt_create();
859863
if (!ins->cmt) {
860864
flb_error("[output] could not create cmetrics context");
861865
return -1;
862866
}
863867

864-
/* Register generic output plugin metrics */
868+
/*
869+
* Register generic output plugin metrics
870+
*/
871+
872+
/* fluentbit_output_proc_records_total */
865873
ins->cmt_proc_records = cmt_counter_create(ins->cmt, "fluentbit",
866874
"output", "proc_records_total",
867875
"Number of processed output records.",
868876
1, (char *[]) {"name"});
877+
cmt_counter_set(ins->cmt_proc_records, ts, 0, 1, (char *[]) {name});
869878

879+
880+
/* fluentbit_output_proc_bytes_total */
870881
ins->cmt_proc_bytes = cmt_counter_create(ins->cmt, "fluentbit",
871882
"output", "proc_bytes_total",
872883
"Number of processed output bytes.",
873884
1, (char *[]) {"name"});
885+
cmt_counter_set(ins->cmt_proc_bytes, ts, 0, 1, (char *[]) {name});
886+
874887

888+
/* fluentbit_output_errors_total */
875889
ins->cmt_errors = cmt_counter_create(ins->cmt, "fluentbit",
876890
"output", "errors_total",
877891
"Number of output errors.",
878892
1, (char *[]) {"name"});
893+
cmt_counter_set(ins->cmt_errors, ts, 0, 1, (char *[]) {name});
879894

895+
896+
/* fluentbit_output_retries_total */
880897
ins->cmt_retries = cmt_counter_create(ins->cmt, "fluentbit",
881898
"output", "retries_total",
882899
"Number of output retries.",
883900
1, (char *[]) {"name"});
901+
cmt_counter_set(ins->cmt_retries, ts, 0, 1, (char *[]) {name});
884902

903+
/* fluentbit_output_retries_failed_total */
885904
ins->cmt_retries_failed = cmt_counter_create(ins->cmt, "fluentbit",
886905
"output", "retries_failed_total",
887906
"Number of abandoned batches because "
888907
"the maximum number of re-tries was "
889908
"reached.",
890909
1, (char *[]) {"name"});
910+
cmt_counter_set(ins->cmt_retries_failed, ts, 0, 1, (char *[]) {name});
911+
891912

913+
/* fluentbit_output_dropped_records_total */
892914
ins->cmt_dropped_records = cmt_counter_create(ins->cmt, "fluentbit",
893915
"output", "dropped_records_total",
894916
"Number of dropped records.",
895917
1, (char *[]) {"name"});
918+
cmt_counter_set(ins->cmt_dropped_records, ts, 0, 1, (char *[]) {name});
896919

920+
/* fluentbit_output_retried_records_total */
897921
ins->cmt_retried_records = cmt_counter_create(ins->cmt, "fluentbit",
898922
"output", "retried_records_total",
899923
"Number of retried records.",
900924
1, (char *[]) {"name"});
925+
cmt_counter_set(ins->cmt_retried_records, ts, 0, 1, (char *[]) {name});
901926

902927
/* old API */
903928
ins->metrics = flb_metrics_create(name);

0 commit comments

Comments
 (0)