|
31 | 31 | #include <fluent-bit/flb_mem.h> |
32 | 32 | #include <fluent-bit/flb_str.h> |
33 | 33 | #include <fluent-bit/flb_scheduler.h> |
| 34 | +#include <fluent-bit/flb_time.h> |
| 35 | +#ifdef FLB_HAVE_METRICS |
| 36 | +#include <fluent-bit/flb_metrics.h> |
| 37 | +#endif |
34 | 38 | #include <string.h> |
35 | 39 |
|
36 | 40 | /* |
@@ -73,6 +77,60 @@ static inline void map_free_task_id(int id, struct flb_config *config) |
73 | 77 | config->task_map[id].task = NULL; |
74 | 78 | } |
75 | 79 |
|
| 80 | +#ifdef FLB_HAVE_METRICS |
| 81 | +static void record_unmatched_route_drop_metrics(struct flb_input_instance *ins, |
| 82 | + struct flb_input_chunk *ic, |
| 83 | + size_t chunk_size) |
| 84 | +{ |
| 85 | + struct flb_router *router; |
| 86 | + uint64_t now; |
| 87 | + double dropped_bytes; |
| 88 | + char *labels[2]; |
| 89 | + |
| 90 | + if (!ins || !ic || !ins->config) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + if (ic->event_type != FLB_INPUT_LOGS || ic->total_records <= 0) { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + router = ins->config->router; |
| 99 | + if (!router) { |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + now = cfl_time_now(); |
| 104 | + labels[0] = (char *) flb_input_name(ins); |
| 105 | + labels[1] = "unmatched"; |
| 106 | + |
| 107 | + dropped_bytes = (double) chunk_size; |
| 108 | + if (dropped_bytes <= 0) { |
| 109 | + ssize_t real_size; |
| 110 | + |
| 111 | + real_size = flb_input_chunk_get_real_size(ic); |
| 112 | + if (real_size > 0) { |
| 113 | + dropped_bytes = (double) real_size; |
| 114 | + } |
| 115 | + else { |
| 116 | + dropped_bytes = 0; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + cmt_counter_add(router->logs_drop_records_total, |
| 121 | + now, |
| 122 | + (double) ic->total_records, |
| 123 | + 2, |
| 124 | + labels); |
| 125 | + |
| 126 | + cmt_counter_add(router->logs_drop_bytes_total, |
| 127 | + now, |
| 128 | + dropped_bytes, |
| 129 | + 2, |
| 130 | + labels); |
| 131 | +} |
| 132 | +#endif |
| 133 | + |
76 | 134 | static int task_collect_output_references(struct flb_config *config, |
77 | 135 | const struct flb_chunk_direct_route *route, |
78 | 136 | struct flb_output_instance ***out_matches, |
@@ -806,6 +864,9 @@ struct flb_task *flb_task_create(uint64_t ref_id, |
806 | 864 |
|
807 | 865 | /* no destinations ?, useless task. */ |
808 | 866 | if (count == 0) { |
| 867 | +#ifdef FLB_HAVE_METRICS |
| 868 | + record_unmatched_route_drop_metrics(i_ins, task_ic, size); |
| 869 | +#endif |
809 | 870 | flb_debug("[task] created task=%p id=%i without routes, dropping.", |
810 | 871 | task, task->id); |
811 | 872 | if (router_context_initialized) { |
|
0 commit comments